Is there a way to modify assembly version, company name, etc using MSBuild command?
I’ve read that dotnet command uses MSBuild internally, but I don’t think that can be used for .NET Framework projects.
Could someone help me?
Thanks in advance
CodePudding user response:
Projects for .Net Framework use the 'legacy' project format. Projects for .Net/.Net Core use the 'SDK style' project format.
The SDK style supports dynamic generation of the AssemblyInfo and supports properties that are used to provide the assembly information (like the version and company name). See "Assembly attribute properties" and note the section on "Migrating from .NET Framework".
The legacy project format doesn't support dynamic generation of the AssemblyInfo but you can roll your own dynamic generation of the AssemblyInfo in a legacy project.
Generating the source file is straight forward. The tricky part is adding the new source file to the Compile
ItemGroup only when a compilation will already otherwise be performed so that incremental builds are not broken. Luckily we can 'borrow' from the SDK style implementation. The following example TestingTarget
will run before compilation but not if the project is otherwise up to date.
<Target Name="TestingTarget" BeforeTargets="BeforeCompile;CoreCompile" DependsOnTargets="PrepareForBuild">
<Message Text="in TestingTarget" Importance="High" />
</Target>