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:
<Project>
<PropertyGroup>
<Version>1.1.0</Version>
<FileVersion>1.1.0</FileVersion>
<Product>Fenergo.Platform.Common</Product>
<Company>Fenergo</Company>
<Copyright>Copyright © Fenergo 2018</Copyright>
</PropertyGroup>
</Project>
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:
<Project>
<PropertyGroup>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<AdditionalFiles Include="..\StyleCop.json" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2" />
</ItemGroup>
</Project>
If you don't have your Directory.Build.props in your root directory, you can import it in the projects which you need it.
<Project>
<!-- Import parent Directory.build.props -->
<Import Project="../Directory.Build.props" />
<!-- Properties common to all test projects -->
<!-- ... -->
</Project>
I hope you found this post helpful,
Happy coding!
Alberto.
Comments
Post a Comment