Maintaining AssemblyInfo for multiple projects

When you are developing an application or manly a NuGet package, you might want to keep the same AssemblyInfo for all your packages, which involves updating each project when you want to publish a new version of your package according to the SemVer convention Semantic Versioning 2.0.0 | Semantic Versioning.

In order to make it easier, with the improvements of dotnet core and the new csproj syntax, which I strongly recommend, MSBuild 15 introduced a pretty cool feature: Solution-wide project properties with Directory.Build.props Customize your build - Visual Studio | Microsoft Docs. Basically, this allows you to define certain properties and use them in all your project in a centralised way, so you don't have to update your projects one by one.

All you have to do is create a new text file named Directory.Build.props and place it where you have your solution file. Here is an example of the properties you can use:

    <Copyright>Copyright © Fenergo 2018</Copyright>

In addition, you can inherit another funcionalities such as analysers. For example, if you want to use the Stylecop.Analyzers for all your project, you can add a Directory.Build.props like this:

    <AdditionalFiles Include="..\StyleCop.json" />
    <PackageReference Include="StyleCop.Analyzers" Version="1.0.2" />

If you don't have your Directory.Build.props in your root directory, you can import it in the projects which you need it.

  <!-- Import parent -->
  <Import Project="../Directory.Build.props" />

  <!-- Properties common to all test projects -->
  <!-- ... -->

I hope you found this post helpful,

Happy coding!



Popular posts from this blog

Multi-language single page applications

Improvement in the Test Explorer for Visual Studio v15.7

Install an SQLite database in your Xamarin app