在构建时设置 .net 核心库程序集/文件/nuget 包版本 [英] Setting .net core library assembly/file/nuget package version at build time

查看:27
本文介绍了在构建时设置 .net 核心库程序集/文件/nuget 包版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在构建时设置我的 .net 核心库的程序集版本(以及文件版本和 nuget 包版本).我的库是使用最新的 Visual Studio 2017 RC 编写的,因此不再有 projects.json 文件,并且由 TeamCity 使用调用 dotnet restore 的标准 powershell 构建脚本构建dotnet build dotnet test 当然还有 dotnet pack.

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.

一直在网上搜索一个优雅的解决方案,但还没有找到任何接近它的东西.我在互联网上所能找到的只是现在已经过时的 xprojprojects.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 builddotnet pack 命令不支持开箱即用.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆