在构建时设置.net核心库程序集/文件/ nuget软件包的版本 [英] Setting .net core library assembly/file/nuget package version at build time
问题描述
我正在设法在构建时设置.net核心库的程序集版本(以及文件版本和nuget软件包版本)。我的库是使用最新的Visual Studio 2017 RC编写的,因此不再有 projects.json
文件,并且由TeamCity使用标准的Powershell构建脚本构建,该脚本调用 dotnet恢复
dotnet构建
dotnet测试
,当然还有 dotnet包
。
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
.
曾经浏览过网络,寻找一种优雅的解决方案,但没有找到任何接近的解决方案。我在互联网上只能找到现在已经过时的 xproj
和 projects.json
格式。
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.
dotnet构建
和 dotnet包
命令确实使我感到惊讶
I'm quite surprised that the dotnet build
and dotnet pack
commands don't support this out of the box.
谢谢:)
推荐答案
万一其他人需要它,请将其添加到您的csproj中:
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>
我们的 PackageId
显然与我们的项目相同名称,但您可以更改。
Our PackageId
is obviously same as our project names, but you can change it.
您可以在csproj中将$(Version)硬编码为此处,或在发布/打包时将其发送:
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
这篇关于在构建时设置.net核心库程序集/文件/ nuget软件包的版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!