Set AssemblyInformationalVersion in AssemblyInfo.cs over msbuild
Parameters
First, you should note that MSBuild properties like $MyInfoText
can only be used in xxxx.xxproj
file and in your situation, it can only be used in myProject.csproj
file rather than the cs file.
To realize your requirements, you can try to use a target which is equivalent to redeploying the parameters in the assembly.cs file in MSBuild. Based on it, you can override its properties from the command line in MSBuild. Only the properties in the XML file can be overridden by the values specified on the command line of msbuild.
Solution
1) install a nuget package called MSBuildTasks into your project.
2) please import MSBuild.Community.Tasks.Targets
which exists under the lib folder of th nuget package. For me, l add it in the xxxx.csproj
file like this on the top of the file:
<Import Project="C:\Users\Admin\source\repos\ConsoleApp\packages\MSBuildTasks.1.5.0.235\tools\MSBuild.Community.Tasks.Targets" />
3) Besides, add these:
<PropertyGroup>
<ProductName>$(AssemblyName)</ProductName>
<CompanyName></CompanyName>
<Version>1.0.0.0</Version>
<MyInfoText>xxx</MyInfoText>
</PropertyGroup>
<ItemGroup>
<AssemblyVersionFiles Include="$(MSBuildProjectDirectory)\Properties\AssemblyInfo.cs" />
</ItemGroup>
<Target Name="AssemblyVersion" Inputs="@(AssemblyVersionFiles)" Outputs="UpdatedAssemblyVersionFiles" BeforeTargets="Build">
<Attrib Files="%(AssemblyVersionFiles.FullPath)" Normal="true" />
<AssemblyInfo
CodeLanguage="CS"
OutputFile="%(AssemblyVersionFiles.FullPath)"
AssemblyProduct="$(ProductName)"
AssemblyTitle="$(ProductName)"
AssemblyCompany="$(CompanyName)"
AssemblyCopyright="Copyright $(CompanyName), All rights reserved."
AssemblyVersion="$(Version)"
AssemblyFileVersion="$(Version)"
AssemblyInformationalVersion="$(MyInfoText)">
<Output TaskParameter="OutputFile" ItemName="UpdatedAssemblyVersionFiles" />
</AssemblyInfo>
</Target>
4) After that, you can use msbuild myProject.csproj /p:MyInfoText=xxxxxx
to overwrite it.
Update 1
Since you do not want to install this nuget package, I suggest you could move its content from the tool folder into your project so that it will be a part of your project.
1) create a folder called newtool under your project
2) copy the content of the tool folder from the nuget package into the newtool folder in your project.


3) change to use this import tag in your xxx.csproj
file
<Import Project="$(ProjectDir)newtool\MSBuild.Community.Tasks.Targets" />
Then you can realize it and be much more convenient.
Hope it could help you.