I’m trying to restructure our projects and one part was moving all versioning information into Directory.build.props.
This works for all projects which are .NET SDK style projects (many of them are multi targeted for .NET Core and .NET 4.8).
For projects which are “old style” (e.g. an old WebForms project) this doesn’t work. But the project references which are SDK style are versioned correctly during the build, so doesn’t seem to be an issue with the Directory.Build.props file, but more with the “old” project format.
The “old style” projects still have an AssemblyInfo.cs (containing such information like the Title) but they don’t contain the versioning attributes.
This is such an AssemblyInfo.cs
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("MyAssembly")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
This is the Directory.Build.props
<Project>
<PropertyGroup>
<Company>OurCompany</Company>
<Copyright>Copyright ©</Copyright>
<Product>OurProduct</Product>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
<Version>1.0.0.0</Version>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
</PropertyGroup>
</Project>
Built are the projects with msbuild with parameters:
/target:Rebuild /fl /flp:Verbosity=normal /flp:Append /property:langversion=latest
And since I’ve seen this may be important, the csproj seems to be correct:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="17.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<Import Project="$(MSBuildExtensionsPath)$(MSBuildToolsVersion)Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)$(MSBuildToolsVersion)Microsoft.Common.props')" />
[...]
I believe this has to do with the existing AssemblyInfo, but I can’t delete it since there are project specific settings.