I'm after a way to set my .net core library's assembly version (and file version and nuget package version) at build time. My library is written using the latest Visual Studio 2017 RC so no more projects.json
file and is being built by TeamCity with a standard powershell buildscript that invokes dotnet restore
dotnet build
dotnet test
and of course dotnet pack
.
Been scanning the web for an elegant solution but haven't found anything even close to it. All I could find on the interweb is for the now obsolete xproj
and projects.json
format.
I'm quite surprised that the dotnet build
and dotnet pack
commands don't support this out of the box.
Thanks :)
Run the pack command Select Build > Configuration Manager, and then set the Active solution configuration to Release. Select the AppLogger project in Solution Explorer, and then select Build > Pack. Visual Studio builds the project and creates the . nupkg file.
The assembly's version number, which, together with the assembly name and culture information, is part of the assembly's identity. This number is used by the runtime to enforce version policy and plays a key part in the type resolution process at run time.
In case anyone else comes along and needs this, add this to your csproj:
<PropertyGroup>
<Version>1.2.3.4</Version>
<PackageId>$(AssemblyName)</PackageId>
<Title>My Super Library</Title>
<AssemblyTitle>$(AssemblyName)</AssemblyTitle>
<Company>AwesomeCo, Inc.</Company>
<Product>My Super Library</Product>
<Copyright>Copyright © AwesomeCo, Inc. 2016-2017</Copyright>
<Description>There can be only one.</Description>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<GenerateAssemblyTitleAttribute>true</GenerateAssemblyTitleAttribute>
<GenerateAssemblyConfigurationAttribute>true</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>true</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>true</GenerateAssemblyProductAttribute>
<GenerateAssemblyCopyrightAttribute>true</GenerateAssemblyCopyrightAttribute>
<GenerateAssemblyVersionAttribute>true</GenerateAssemblyVersionAttribute>
<GenerateAssemblyInformationalVersionAttribute>true</GenerateAssemblyInformationalVersionAttribute>
</PropertyGroup>
Our PackageId
is obviously same as our project names, but you can change it.
You can either hard-code $(Version) here in your csproj, or send it in when you publish/pack:
dotnet publish /property:Version=1.2.3.4
For those who still wonder how to do this without heavily modifying your csproj
files, you can pass msbuild
params along with your dotnet
commands, in this case, we could simply do
dotnet build /p:Version=1.2.3
dotnet publish /p:Version=1.2.3
this will set both the assembly and file version to 1.2.3
. I have verified with .Net Core 2 SDK
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With