简体   繁体   English

当操作来自 NuGet package 时,如何在多目标项目上操作 Packageversion

[英]How can I manipulate the Packageversion on a multi target project when manipulation comes from a NuGet package

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).我有一个 NuGet package 和一个目标文件,它根据当前上下文操作 PackageVersion(当分支是主分支时,它会创建一个预览)。

This is working well on a normal project but when I use this in a multi target project it's not working.这在普通项目上运行良好,但当我在多目标项目中使用它时,它不起作用。

How can I correct this?我该如何纠正这个问题?

I have attached a sample project.我附上了一个示例项目。 https://1drv.ms/u/s?At1IZ7t_aXW-iNRchOhliGP8dunGHg?e=11dW4F To reproduce the problem: https://1drv.ms/u/s?At1IZ7t_aXW-iNRchOhliGP8dunGHg?e=11dW4F要重现问题:

  1. Unzip all files解压所有文件
  2. You need a local NuGet Feed您需要本地 NuGet Feed
  3. Entry the name of your local NuGet Feed in BuildConfig/publish.bat在 BuildConfig/publish.bat 中输入本地 NuGet Feed 的名称
  4. Call publish.bat in BuildConfig在 BuildConfig 中调用 publish.bat
  5. Run "do.net pack" in Consumer在 Consumer 中运行“do.net pack”

This creates a package of consumer with version 1.0.0.这将创建一个 package 版本为 1.0.0 的消费者。 This should bie 1.0.0-xdev.这应该是 1.0.0-xdev。

When you change Consumer.csproj so that TargetFramework is used the correct version is created当您更改 Consumer.csproj 以便使用 TargetFramework 时,会创建正确的版本

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我尝试了目标之外的版本修改,但是当在 Directory.Build.Targets 文件中指定版本号时,这会导致问题

I have tried different BeforeTargets in but nothing worked.我尝试了不同的 BeforeTargets 但没有任何效果。

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.您使用像<TargetFrameworks.net461</TargetFrameworks>这样的目标框架属性时, nuget package 的build文件夹不能正常运行,它不能为多目标框架服务,只能为单目标框架服务。

Instead , you should abandon build and use buildCrossTargeting .相反,您应该放弃build并使用buildCrossTargeting

Under BuildConfig project, if it is a new sdk project, please use this BuildConfig工程下,如果是新建sdk工程,请使用这个

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

If you use nuspec file, you should use this undr the file:如果你使用nuspec文件,你应该在文件下使用这个:

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

You should note that the xxx.targets files should be under buildCrossTargeting folder directly without any sub folders, otherwise, it will not work.请注意xxx.targets文件应直接位于buildCrossTargeting文件夹下,没有任何子文件夹,否则将无法运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Nuget:如何确定哪个项目正在引用程序包? - Nuget: how can I tell which project is referencing a package? 如何从Nuget包中选择目标框架 - How to choose target framework from Nuget package 在发布我自己的 Nuget ZEFE0DE8E604A7C68D 时,如何将项目参考指定为 Nuget package 参考? - How do I specify a project reference as a Nuget package reference when publishing my own Nuget package? 将 NuGet package 推送到 nuget.org 时,如何发布文档? - How can I publish documentation when pushing a NuGet package to nuget.org? 如何使用 xmldocument 安装 nuget package - How can i install a nuget package with xmldocument 我无法为我从 git 克隆的项目打开 NuGet Package 管理器 - I can't open NuGet Package Manager for a project that i cloned from git 如何在Visual Studio外部使用nuget包管理器从命令行安装/更新包? - How can I use the nuget Package Manager outside Visual Studio to install/update a package from the commandline? 在Visual Studio中构建项目时如何安装Nuget包 - How install Nuget package when building project in Visual Studio 如何更改nuget包的目标目录结构 - How to change target directories structure of nuget package 如何在我的Visual Studio扩展中将Nuget包添加到项目中? - How can I add a Nuget package to a project in my Visual Studio extension?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM