'Update VersionPrefix with AssemblyVersion
I would like to automatically update the VersionPrefix with AssemblyVersion. I'm trying to set versionPrefix via csproj with this $(AssemblyVersion)
My csproj look like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<OutputType>Library</OutputType>
<AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<UseWindowsForms>true</UseWindowsForms>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
</PropertyGroup>
<PropertyGroup>
<StartupObject/>
<VersionPrefix>$(AssemblyVersion)</VersionPrefix>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<RunAnalyzersDuringBuild>True</RunAnalyzersDuringBuild>
<RunAnalyzersDuringLiveAnalysis>True</RunAnalyzersDuringLiveAnalysis>
<Copyright>$(AssemblyCopyright)</Copyright>
<AssemblyVersion>$(AssemblyVersion)</AssemblyVersion>
<FileVersion>$(AssemblyFileVersion)</FileVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<OutputPath>bin\x64\Debug\</OutputPath>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<OutputPath>bin\x86\Debug\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
</PropertyGroup>
Any idea?
Solution 1:[1]
You set your AssemblyVersion
to be equal to itself. That's a self referential loop. You're lucky the compiler didn't enter an endless loop.
I think it's important to include why. For example, I wanted to sync my NuGet package version with my Assembly Version. I don't want to enter the version multiple times.
I used this:
<AssemblyVersion>1.1.0.0</AssemblyVersion>
<FileVersion>$(AssemblyVersion)</FileVersion>
<Version>$(AssemblyVersion)</Version>
Now I set the version once and it changes my NuGet package as well as the file version!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | HackSlash |