当操作来自NuGet包时,如何在多目标项目上操作Packageversion [英] How can I manipulate the Packageversion on a multi target project when manipulation comes from a NuGet package

查看:78
本文介绍了当操作来自NuGet包时,如何在多目标项目上操作Packageversion的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有目标文件的NuGet包,该文件根据当前上下文操纵PackageVersion(当分支为master时,它会创建一个预览).

I have a NuGet package with a targets file which manipulates the PackageVersion depending on the current context (When the branch is master it's creates a preview).

这在正常项目上运行良好,但是当我在多目标项目中使用它时,则无法正常工作.

This is working well on a normal project but when I use this in a multi target project it's not working.

我该如何纠正?

我已经附上了一个示例项目. https://1drv.ms/u/s!At1IZ7t_aXW-iNRchOhliGP8dunGHg?11dW4F 重现该问题:

I have attached a sample project. https://1drv.ms/u/s!At1IZ7t_aXW-iNRchOhliGP8dunGHg?e=11dW4F To reproduce the problem:

  1. 解压缩所有文件
  2. 您需要本地的NuGet Feed
  3. 在BuildConfig/publish.bat中输入本地NuGet Feed的名称
  4. 在BuildConfig中调用publish.bat
  5. 运行"dotnet pack"在消费者中

这将创建一个版本为1.0.0的使用者软件包.应该使用1.0.0-xdev.

This creates a package of consumer with version 1.0.0. This should bie 1.0.0-xdev.

当您更改Consumer.csproj以便使用TargetFramework时,将创建正确的版本

When you change Consumer.csproj so that TargetFramework is used the correct version is created

我尝试在目标外部进行版本修改,但是当在Directory.Build.Targets文件中指定版本号时,这会导致问题

I have tried the version modification outside of the target but this leads to problems when the version number is specified in a Directory.Build.Targets file

我尝试了其他的BeforeTargets,但没有任何效果.

I have tried different BeforeTargets in but nothing worked.

推荐答案

何时,您使用 multi-targetframeworks 属性,例如< TargetFrameworks> net461</TargetFrameworks>; ,nuget包的 build 文件夹无法正常工作,并且不能用于多目标框架,仅适用于单个标记框架.

When you use multi-targetframeworks property like <TargetFrameworks>net461</TargetFrameworks>, build folder of the nuget package cannot act well and it cannot service for multi-target frameworks, only for single taget framework.

相反,您应该放弃 build 并使用 buildCrossTargeting .

Instead, you should abandon build and use buildCrossTargeting.

BuildConfig 项目下,如果它是新的sdk项目,请使用此

Under BuildConfig project, if it is a new sdk project, please use this

<ItemGroup>
<None Include="BuildConfig.targets" Pack="true" PackagePath="buildCrossTargeting" />"
</ItemGroup>

如果使用 nuspec 文件,则应使用此undr文件:

If you use nuspec file, you should use this undr the file:

<file src="BuildConfig.targets" target="buildCrossTargeting/" />

您应注意 xxx.targets 文件应直接位于 buildCrossTargeting 文件夹下,而没有任何子文件夹,否则,它将不起作用

You should note that the xxx.targets files should be under buildCrossTargeting folder directly without any sub folders, otherwise, it will not work.

这篇关于当操作来自NuGet包时,如何在多目标项目上操作Packageversion的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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