Initialize projects script

Spread the love

I have a preferred Visual Studio solution layout. It is basically as follows, using MyProj as a sample name:

  • MyProj: Solution root.
    • bin: All built binaries go here.
    • external: External binary dependencies (e.g. unit test runners).
    • source: Root of source code projects.
      • MyProj.App: Console application.
      • MyProj.Core: Core library.
    • test: Root of test code projects.
      • MyProj.Test.Unit: Unit test library.

I have initialized enough project layouts manually that I felt the need to write a PowerShell script to save on future effort. Perhaps you have a use for it as well?

Get the script here: InitProjects.cmd

The script generates a layout as above with solution and project files compatible with Visual Studio [Express] 2013. It automatically creates a StyleCop settings file with my preferred rule set and copies over xUnit.net dependencies for unit testing.

Example usage and output:


> InitProjects.cmd D:\Temp\z MyProj MyCompany %public%\Programs\xUnit.net
Preparing project 'MyProj.App'...
Writing file 'D:\Temp\z\MyProj\source\MyProj.App\MyProj.App.csproj'...
Writing file 'D:\Temp\z\MyProj\source\MyProj.App\Program.cs'...
Writing file 'D:\Temp\z\MyProj\source\MyProj.App\Properties\AssemblyInfo.cs'...
Preparing project 'MyProj.Core'...
Writing file 'D:\Temp\z\MyProj\source\MyProj.Core\MyProj.Core.csproj'...
Writing file 'D:\Temp\z\MyProj\source\MyProj.Core\Class1.cs'...
Writing file 'D:\Temp\z\MyProj\source\MyProj.Core\Properties\AssemblyInfo.cs'...
Preparing project 'MyProj.Test.Unit'...
Writing file 'D:\Temp\z\MyProj\test\MyProj.Test.Unit\MyProj.Test.Unit.csproj'...
Writing file 'D:\Temp\z\MyProj\test\MyProj.Test.Unit\Test1.cs'...
Writing file 'D:\Temp\z\MyProj\test\MyProj.Test.Unit\Properties\AssemblyInfo.cs'...
Preparing StyleCop settings file...
Writing file 'D:\Temp\z\MyProj\StyleCop.settings'...
Preparing solution file...
Writing file 'D:\Temp\z\MyProj\MyProj.sln'...
Copying xUnit.net dependencies from 'C:\Users\Public\Programs\xUnit.net' to 'D:\Temp\z\MyProj\external\xUnit.net'...

To ensure everything worked correctly, open MyProj.sln in Visual Studio and compile it. You should see output like the following:

1>------ Build started: Project: MyProj.Core, Configuration: Debug Any CPU ------
1> MyProj.Core -> D:\temp\z\MyProj\bin\Debug\MyProj.Core.dll
2>------ Build started: Project: MyProj.App, Configuration: Debug Any CPU ------
3>------ Build started: Project: MyProj.Test.Unit, Configuration: Debug Any CPU ------
2> MyProj.App -> D:\temp\z\MyProj\bin\Debug\MyProj.App.exe
3> MyProj.Test.Unit -> D:\temp\z\MyProj\bin\Debug\MyProj.Test.Unit.dll
3> xUnit.net MSBuild runner (32-bit .NET 4.0.30319.18408)
3> xunit.dll: Version 1.9.2.1705
3> Test assembly: D:\temp\z\MyProj\bin\Debug\MyProj.Test.Unit.dll
3> Tests: 1, Failures: 0, Skipped: 0, Time: 0.127 seconds
========== Build: 3 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

Note that StyleCop and xUnit.net run automatically on each build. This means that StyleCop errors and xUnit.net unit test failures will break the build — just the way I like it!

To ensure the binaries were built correctly, “Start without debugging” (default shortcut Ctrl+F5) and you should observe the following output:

Hello, world!
Press any key to continue . . .

Enjoy your newfound productivity!

One thought on “Initialize projects script

Leave a Reply

Your email address will not be published. Required fields are marked *