Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update VersionPrefix with AssemblyVersion

Tags:

.net

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?

like image 235
Hytac Avatar asked Apr 18 '26 08:04

Hytac


1 Answers

You've 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!

like image 162
HackSlash Avatar answered Apr 22 '26 01:04

HackSlash



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!