I am trying to set the version number to something I want (read they want me to do). They want a specific format, and I need to set the version of out programme.
I tried to use a UsingTask to set a PropertyGroup variable. My UsingTask is working.
All this is new to me, I managed to get the code below. Now, how can I set the local project variable? My initial value is used, next I want to set it programmatically in the UsingTask
This is all done in the *.csproj file
<Project Sdk="Microsoft.NET.Sdk">
<!-- my additional project variable, used below -->
<PropertyGroup Label="UserMacros">
<AssemblyVersion>1.2.3.5</AssemblyVersion>
</PropertyGroup>
<UsingTask TaskName="EnvVarSet"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<Task>
<Code Type="Fragment" Language="cs">
<![CDATA[
// here I want to set the version number to our format
Log.LogMessage(MessageImportance.High, "**** Setting variables");
System.Environment.SetEnvironmentVariable("AssemblyVersion", "1.5.6.7");
var a = Environment.GetEnvironmentVariable("AssemblyVersion");
Log.LogMessage(MessageImportance.High, "**** Value is: " +a);
]]>
</Code>
</Task>
</UsingTask>
<PropertyGroup>
<OutputType>WinExe</OutputType>
<!-- the version number I want to set -->
<Version>$(AssemblyVersion)</Version>
<!-- this does not work -->
<!-- <Version>$([System.Environment]::GetEnvironmentVariable('AssemblyVersion'))</Version>-->
other values....
</PropertyGroup>
//more project....
<Target Name="BeforeBeforeBuild" BeforeTargets="BeforeBuild">
<EnvVarSet />
<Message Text="***** AssemblyVersionis now: $([System.Environment]::GetEnvironmentVariable('AssemblyVersion'))"/>
</Target>
</Project>