Some useful scripts.
Allows you to create a project, using any template available with dotnet new, and it associated xunit test project.
Optionally, you can also create a functional tests project which automatically import Microsoft.AspNetCore.App and Microsoft.AspNetCore.Mvc.Testing.
The project structure is as follow:
(root)
src
{project name}
test
{project name}.Tests
(optional){project name}.FunctionalTests
(optional){solution name}.sln
From the source code directory, execute the following command:
To install it locally, using the source:
Import-Module .\dotnet-new\dual-projects\dual-projects.psm1
# Example from a local directory to test scripts changes, you can load the module with absolute path:# To unload the module, close the PowerShell consoleImport-Module F:\Repos\ForEvolve.Scripts\dotnet-new\dual-projects\dual-projects.psm1You can also use the published version, on MyGet, by executing the following commands:
Register ForEvolve NuGet feed as ForEvolveFeed:
Import-Module PowerShellGet
$PSGalleryPublishUri='https://www.myget.org/F/forevolve/api/v2/package'$PSGallerySourceUri='https://www.myget.org/F/forevolve/api/v2'Register-PSRepository-Name ForEvolveFeed -SourceLocation $PSGallerySourceUri-PublishLocation $PSGalleryPublishUri# If you trust my feed, you can run the following command to get rid of the anoying confirmation# You will need an elevated PowerShell terminalSet-PSRepository-Name "ForEvolveFeed"-InstallationPolicy TrustedInstall the module from that custom MyGet feed:
# For all users (required an elevated terminal)Install-Module-Name "dual-projects"-RequiredVersion "1.1.2"-Repository ForEvolveFeed
# Only for the current userInstall-Module-Name "dual-projects"-RequiredVersion "1.1.2"-Repository ForEvolveFeed -Scope CurrentUserYou may also have to import the module:
Import-Module dual-projectsYou may need to update your execution policy, with Set-ExecutionPolicy, to be able to run PowerShell script file using the following command:
Set-ExecutionPolicy UnrestrictedYou need to run PowerShell in admin mode to execute that command.
| Parameter | Alias | Switch? | Required | Version | Default Value | Description |
|---|---|---|---|---|---|---|
-projectName | -p | No | Yes | 1.0.0 | The name of the project that you want to create, for exmaple: SomeCoolProject. | |
-projectTemplate | -t | No | No | 1.0.0 | web | The dotnet new template to use for the main project. |
-createSolution | -create-sln | Yes | No | 1.0.0 | $false | Specify if you want to create a solution. |
-solutionName | -s | No | No | 1.0.0 | The name of the solution to create if it differs from the project name. | |
-mkdir | No | No | 1.0.0 | $true | Specify if you want to make a new directoy for the solution. | |
-noBuild | -no-build | Yes | No | 1.0.0 | If specified, dotnet build will not run after the projects creation. | |
-addFunctionalTests | -add-functional-tests | Yes | No | 1.1.0 | If specified, Add-FunctionalTests will be called to add a function tests project. | |
-customTestsPropsFile | -tests-props | No | No | 1.1.0 | $null | Allow specifying a .props file that will be imported at the top of the unit test project. |
-customFunctionalTestsPropsFile | -functional-tests-props | No | No | 1.1.0 | $null | Allow specifying a .props file that will be imported at the top of the functional test project. |
How to create a project and a test project (named SomeCoolProject) in an existing solution:
Add-DualProjects-projectName SomeCoolProjectHow to create a project, a test project (named SomeCoolProject) and a solution:
Add-DualProjects-projectName SomeCoolProject -createSolutionHow to create a class library project and a test project (named SomeCoolProject) in an existing solution:
Add-DualProjects-projectName SomeCoolProject -projectTemplate classlibHow to create a class library project, a test project (named SomeCoolProject) and a solution:
Add-DualProjects-projectName SomeCoolProject -projectTemplate classlib -createSolutionHow to create an MVC project and a test project (named SomeCoolProject) in an new solution named some-solution.sln in the current directory:
Add-DualProjects-projectName SomeCoolProject -projectTemplate mvc -createSolution -solutionName some-solution.sln -mkdir $falseTo tell the script not to build the solution, you can specify -noBuild or -no-build:
Add-DualProjects-p SomeCoolProject -t mvc -s some-solution.sln -mkdir $false-no-build -create-slnHow to create a project named SomeCoolProject, a unit tests project, and a functional tests project in the default, existing, solution:
Add-DualProjects-projectName SomeCoolProject -add-functional-testsHow to create a project named SomeCoolProject, a unit tests project, and a functional tests project in the default, existing, solution with each test project importing its own props file.
This command also includes the -no-build flag which can become handy when GenerateDocumentationFile is set to true and TreatWarningsAsErrors is also set to true (in a Directory.Build.props file for example).
Add-DualProjects-projectName SomeCoolProject -add-functional-tests -functional-tests-props ..\FunctionalTests.Build.props -customTestsPropsFile ..\UnitTests.Build.props -no-build| Parameter | Alias | Switch? | Required | Version | Default Value | Description |
|---|---|---|---|---|---|---|
-projectName | -p | No | Yes | 1.1.0 | The name of the project that you want to create, for exmaple: SomeCoolProject. | |
-solutionName | -s | No | No | 1.1.0 | The name of the solution to add your functional tests project to if there is more than one in the directory. | |
-noBuild | -no-build | Yes | No | 1.1.0 | If specified, dotnet build will not run after the projects creation. | |
-customPropsFile | -props | No | No | 1.1.0 | $null | Allow specifying a .props file that will be imported at the top of the functional test project. |
How to create a functional tests project for the project SomeCoolProject:
Add-FunctionalTests-p SomeCoolProjectThis will create a xunit project into
test/SomeCoolProject.FunctionalTestslinked tosrc/SomeCoolProject.
How to create a functional tests project for the project SomeCoolProject and include a props file located into test/FunctionalTests.Build.props:
Add-FunctionalTests-p SomeCoolProject -props ..\FunctionalTests.Build.propsThis will add
<Import Project="..\FunctionalTests.Build.props" />at the top of the project file ( under<Project Sdk="Microsoft.NET.Sdk.Web">).
Use a custom MyGet feed:
Import-Module PowerShellGet
$PSGalleryPublishUri='https://www.myget.org/F/forevolve/api/v2/package'$PSGallerySourceUri='https://www.myget.org/F/forevolve/api/v2'Register-PSRepository-Name ForEvolveFeed -SourceLocation $PSGallerySourceUri-PublishLocation $PSGalleryPublishUri# To unregister a sourceUnregister-PSRepository-Name ForEvolveFeed
# To trust the sourceSet-PSRepository-Name "ForEvolveFeed"-InstallationPolicy TrustedInstall the module from that custom MyGet feed:
# Only for the current userInstall-Module-Name "dual-projects"-RequiredVersion "1.1.2"-Repository ForEvolveFeed -Scope CurrentUser
# For all users (required an elevated terminal)Install-Module-Name "dual-projects"-RequiredVersion "1.1.2"-Repository ForEvolveFeed
# Update the module (force is required to overrite the old version)Update-Module-Name "dual-projects"-RequiredVersion "1.1.2"-Force
# List installed modulesGet-InstalledModule-Name "dual-projects"# Uninstall the moduleUninstall-Module-Name "dual-projects"-AllVersionsPublish to that custom MyGet feed:
$APIKey='YOUR-API-KEY'
cd dotnet-new
Publish-Module-Path dual-projects -NuGetApiKey $APIKey-Repository ForEvolveFeed -VerboseRead feeds list: Get-PSRepository
Create a module manifest: New-ModuleManifest -Path dual-projects.psd1
- Update the module description.
- Specify
FunctionsToExportat the module level.
- Fix: Convert the csproj file path to absolute before reading it to make sure it works everytime.
- Add the
Add-FunctionalTestsfunction. - Add functional tests options to the
Add-DualProjectsfunction (which now act more like "add three projects" than "add two projects"). - Unit tests and fucntional tests projects now adds the right
RootNamespacein theircsprojfile.
- Initial release of the
Add-DualProjectsfunction.