|
1 | | -# Script.PS.Create-VSSolution |
2 | | -Create a solution skeleton with src folder, three library projects, and one UI project. |
| 1 | +[![downloads][downloads-shield]][downloads-url] [![Contributors][contributors-shield]][contributors-url] [![Forks][forks-shield]][forks-url] [![Stargazers][stars-shield]][stars-url] [![Issues][issues-shield]][issues-url] [![License][license-shield]][license-url] [![LinkedIn][linkedin-shield]][linkedin-url] |
| 2 | + |
| 3 | +# ![Logo][Logo] Create VSSolution File - Clean Architecture |
| 4 | +Create a solution file for Visual Studio with a clean architecture. |
| 5 | + |
| 6 | +## Overview |
| 7 | +This PowerShell script automates the creation of a Visual Studio solution structure with multiple projects, including a UI project (WPF, WinUI, or MAUI) and associated class libraries. It sets up a standard folder layout and configures project references. |
| 8 | +The script is designed to streamline the initial setup of a .NET solution, saving time and ensuring consistency across projects. |
| 9 | + |
| 10 | +## Features |
| 11 | +- Creates a solution folder with a `src` subfolder. |
| 12 | +- Generates three class library projects: `Domain`, `Core`, and `Infrastructure`. |
| 13 | +- Generates a UI project based on user selection (WPF). |
| 14 | + |
| 15 | +## Quick Start |
| 16 | + |
| 17 | +### Prerequisites |
| 18 | +- .NET SDK installed and `dotnet` available on PATH. |
| 19 | + |
| 20 | +### Installation |
| 21 | + |
| 22 | + |
| 23 | +## Make `Create-VSSolution.ps1` available globally |
| 24 | +There are a few simple options to make the script available from any location. This repository includes an installer script `install.ps1` that automates common steps. |
| 25 | + |
| 26 | +Quick installer examples |
| 27 | + |
| 28 | +- Install (default): add `%USERPROFILE%\Scripts` to your user PATH. If you run `install.ps1` with no action flags it will default to `-AddToPath` (and currently also sets the `-CreateProfileFunction` flag by default). |
| 29 | + |
| 30 | + `.\install.ps1` or from repo root: |
| 31 | + `.\install.ps1` (adjust path as needed) |
| 32 | + |
| 33 | +- Install + request a wrapper function to be added to your PowerShell profile (note: the installer exposes `-CreateProfileFunction`, but the current implementation does not create the wrapper automatically): |
| 34 | + |
| 35 | + `.\install.ps1 -AddToPath -CreateProfileFunction` |
| 36 | + |
| 37 | +- Install as a simple PowerShell module: |
| 38 | + |
| 39 | + `.\install.ps1 -AsModule` |
| 40 | + |
| 41 | +- Remove everything added by the installer (script, shim entry removal logic, module, PATH entry, and profile wrapper removal logic): |
| 42 | + |
| 43 | + `.\install.ps1 -Delete` |
| 44 | + |
| 45 | +Notes about what the installer does (current behavior) |
| 46 | + |
| 47 | +- Default behavior: when called without action switches the installer will perform `-AddToPath`. The script also sets `-CreateProfileFunction` by default in the parameter handling, but the wrapper creation is not implemented in the current script. |
| 48 | +- It copies `Create-VSSolution.ps1` into the install folder (default: `%USERPROFILE%\Scripts`) when the source script is available in the repository. |
| 49 | +- The installer exposes flags and removal logic for a `Create-VSSolution.cmd` shim and a PowerShell profile wrapper. However, the current implementation does not create the shim or the profile wrapper; the `-Delete` and `-DeleteProfileFunction` flags attempt to remove wrapper/shim artifacts if they already exist. |
| 50 | +- It can install the script as a minimal PowerShell module under `%USERPROFILE%\Documents\PowerShell\Modules\Create-VSSolution\` when `-AsModule` is used. |
| 51 | +- It supports `-Force` to overwrite existing files without prompting (when the copy logic runs it respects `-Force`). |
| 52 | +- The installer has a `-VerboseMode` parameter controlling informational output (numeric verbosity levels). |
| 53 | + |
| 54 | +Using the wrapper or shim |
| 55 | + |
| 56 | +- PowerShell wrapper: if you add a wrapper to your profile manually, reload your profile (`. $PROFILE`) or restart PowerShell, then run: |
| 57 | + |
| 58 | + `Create-VSSolution` |
| 59 | + |
| 60 | +- CMD/shim: if you create a shim manually and add the install folder to your PATH you can run from any shell: |
| 61 | + |
| 62 | + `Create-VSSolution` |
| 63 | + |
| 64 | +Troubleshooting and environment |
| 65 | + |
| 66 | +- If you downloaded the script from the internet, unblock it first: |
| 67 | + `Unblock-File .\Create-VSSolution.ps1` |
| 68 | +- Ensure execution policy allows running scripts: |
| 69 | + `Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned` |
| 70 | +- If PATH changes don't appear in an open shell, either restart the shell or add the folder to the session manually: |
| 71 | + `$env:Path += ';' + "$env:USERPROFILE\Scripts"` |
| 72 | + |
| 73 | +## Adjusting the Target Framework Moniker (TFM) |
| 74 | +The projects created by the script use a default TFM. To change the TFM (for example from `net6.0` to `net7.0`), you have several options: |
| 75 | + |
| 76 | +1. Edit the script before running |
| 77 | +- Open `src\Create-VSSolution.ps1` and look for the variable that sets the TFM (commonly something like `$TFM = 'net6.0'`). Change it to the desired TFM (for example `'net7.0'`). |
| 78 | + |
| 79 | +2. Use the `-f` / `--framework` option when using `dotnet new` directly |
| 80 | +- When creating projects manually, pass the framework to the template: `dotnet new classlib -f net7.0 -o MyLib`. |
| 81 | + |
| 82 | +3. Change TFMs for generated projects after creation (bulk replace) |
| 83 | +- Run a PowerShell replace over the generated project files. Example to replace `net6.0` with `net7.0`: |
| 84 | + |
| 85 | + `Get-ChildItem -Path . -Recurse -Filter *.csproj | ForEach-Object { (Get-Content $_.FullName) -replace 'net6.0', 'net7.0' | Set-Content $_.FullName } |
| 86 | +` |
| 87 | + |
| 88 | +- Alternatively, use `sed`/`perl` or an editor to update the `<TargetFramework>` element in each `.csproj`. |
| 89 | + |
| 90 | +Notes |
| 91 | +- Ensure all referenced libraries and NuGet packages support the target TFM you choose. |
| 92 | +- After changing TFMs, run `dotnet restore` and `dotnet build` to validate everything compiles. |
| 93 | + |
| 94 | +## How to use `Create-VSSolution.ps1` |
| 95 | + |
| 96 | +The generator script is located at `src\Create-VSSolution.ps1`. You can run it directly from the repository or after installing it with `install.ps1`. |
| 97 | + |
| 98 | +Prerequisites |
| 99 | + |
| 100 | +- .NET SDK installed and `dotnet` available on PATH. |
| 101 | +- On Windows, additional templates may be required for WPF/WinUI projects (Windows App SDK / WinUI templates). |
| 102 | +- Ensure execution policy allows running local scripts: `Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned`. |
| 103 | + |
| 104 | +Run the script directly (no install) |
| 105 | + |
| 106 | +- From the repository root: |
| 107 | + |
| 108 | + `& "Create-VSSolution.ps1" -SolutionName MyApp -ProjectType wpf` |
| 109 | + |
| 110 | +- From the `src` folder: |
| 111 | + |
| 112 | + `& ".\src\Create-VSSolution.ps1" -SolutionName MyApp -ProjectType wpf` |
| 113 | + |
| 114 | +Installed usage (recommended) |
| 115 | + |
| 116 | +- If you used `install.ps1 -AddToPath` (the default installer behavior), you can run the installed script after adding `\Scripts` folder to PATH: |
| 117 | + |
| 118 | + `Create-VSSolution -SolutionName MyApp -ProjectType wpf` |
| 119 | + |
| 120 | +- If you prefer a cross-shell command and create a shim manually in the install folder, the shim would let you call the same `Create-VSSolution` command from cmd.exe or other shells once the install folder is on PATH. |
| 121 | + |
| 122 | +Parameters for `install.ps1` |
| 123 | + |
| 124 | +- `-InstallPath` (default: `%USERPROFILE%\\Scripts`): Destination folder for the script and any shims. |
| 125 | +- `-AddToPath`: Add `InstallPath` to the user's PATH environment variable. |
| 126 | +- `-CreateProfileFunction`: Flag exposed by the installer to request a wrapper function in the PowerShell profile (currently not implemented). |
| 127 | +- `-DeleteProfileFunction`: Flag to remove a profile wrapper if present. |
| 128 | +- `-Delete`: Remove installed script, module folder, PATH entry and profile wrapper lines (best-effort removal behavior). |
| 129 | +- `-AsModule`: Install `Create-VSSolution.ps1` as a simple PowerShell module under `Documents\PowerShell\Modules\Create-VSSolution`. |
| 130 | +- `-Force`: Overwrite existing files without prompting when copying. |
| 131 | +- `-VerboseMode`: Numeric verbosity level for installer output (0..n). |
| 132 | + |
| 133 | +Examples |
| 134 | + |
| 135 | +- Add the scripts folder to user PATH (default behavior when called with no action switches): |
| 136 | + `.\install.ps1` |
| 137 | + |
| 138 | +- Install as a module (overwrite existing module files if needed): |
| 139 | + `.\install.ps1 -AsModule -Force` |
| 140 | + |
| 141 | +Notes |
| 142 | + |
| 143 | +- The script uses `net8.0` by default for generated projects. Edit `src\Create-VSSolution.ps1` to change the TFM. |
| 144 | +- After installing with `-CreateProfileFunction` (once wrapper creation is implemented), reload your profile (`. $PROFILE`) or restart PowerShell to use the wrapper immediately. |
| 145 | + |
| 146 | +Troubleshooting |
| 147 | + |
| 148 | +- If a `dotnet new` template fails, install the required SDKs/templates and restart your shell. |
| 149 | +- If commands still fail due to script blocking, run `Unblock-File` on the script and set an appropriate execution policy. |
| 150 | + |
| 151 | +## Contributing |
| 152 | +Contributions are welcome. Please follow the guidelines in `CONTRIBUTING.md` and open issues or pull requests. |
| 153 | + |
| 154 | +See [CONTRIBUTING.md](CONTRIBUTING.md) |
| 155 | + |
| 156 | +## Reporting Bugs |
| 157 | +1. Go to the Issues page: [GitHub Issues][githubIssue-url] |
| 158 | +2. Click "New Issue" and provide steps to reproduce, expected behavior, actual behavior, environment, and attachments (logs/screenshots). |
| 159 | + |
| 160 | +## License |
| 161 | +Distributed under the AGPL-3.0 License. See [LICENSE.txt](LICENSE.txt) or [license link][license-url]. |
| 162 | + |
| 163 | +## Contact |
| 164 | +Jens Tirsvad Nielsen - [LinkedIn][linkedin-url] |
| 165 | + |
| 166 | +## Acknowledgments |
| 167 | +Thanks to contributors and the open-source community. |
| 168 | + |
| 169 | +<!-- MARKDOWN LINKS & IMAGES --> |
| 170 | +[contributors-shield]: https://img.shields.io/github/contributors/Tirsvad/Script.PS.Create-VSSolution?style=for-the-badge |
| 171 | +[contributors-url]: https://github.com/Tirsvad/Script.PS.Create-VSSolution/graphs/contributors |
| 172 | +[forks-shield]: https://img.shields.io/github/forks/Tirsvad/Script.PS.Create-VSSolution?style=for-the-badge |
| 173 | +[forks-url]: https://github.com/Tirsvad/Script.PS.Create-VSSolution/network/members |
| 174 | +[stars-shield]: https://img.shields.io/github/stars/Tirsvad/Script.PS.Create-VSSolution?style=for-the-badge |
| 175 | +[stars-url]: https://github.com/Tirsvad/Script.PS.Create-VSSolution/stargazers |
| 176 | +[issues-shield]: https://img.shields.io/github/issues/Tirsvad/Script.PS.Create-VSSolution?style=for-the-badge |
| 177 | +[issues-url]: https://github.com/Tirsvad/Script.PS.Create-VSSolution/issues |
| 178 | +[license-shield]: https://img.shields.io/github/license/Tirsvad/Script.PS.Create-VSSolution?style=for-the-badge |
| 179 | +[license-url]: https://github.com/Tirsvad/Script.PS.Create-VSSolution/blob/master/LICENSE.txt |
| 180 | +[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=for-the-badge&logo=linkedin&colorB=555 |
| 181 | +[linkedin-url]: https://www.linkedin.com/in/jens-tirsvad-nielsen-13b795b9/ |
| 182 | +[githubIssue-url]: https://github.com/Tirsvad/Script.PS.Create-VSSolution/issues/ |
| 183 | +[logo]: https://raw.githubusercontent.com/Tirsvad/Script.PS.Create-VSSolution/main/images/logo/32x32/logo.png |
| 184 | + |
| 185 | + |
| 186 | +[downloads-shield]: https://img.shields.io/github/downloads/Tirsvad/Script.PS.Create-VSSolution/total?style=for-the-badge |
| 187 | +[downloads-url]: https://github.com/Tirsvad/Script.PS.Create-VSSolution/releases |
| 188 | + |
| 189 | +<!-- screenshots --> |
| 190 | +<!-- |
| 191 | +[screenshot1]: https://raw.githubusercontent.com/Tirsvad/Script.PS.Create-VSSolution/main/images/small/Screenshot1.png |
| 192 | +[screenshot1-url]: https://raw.githubusercontent.com/Tirsvad/Script.PS.Create-VSSolution/main/images/Screenshot1.png |
| 193 | +--> |
0 commit comments