使用GeneratePackageOnbuild和版本修补创建一个Nuget软件包
我一直在努力的一段时间:
我有一个“传统”(即非SDK)CSPROJ文件。我想创建一个Nuget软件包。这很容易,但是魔鬼隐藏在细节中,最终我可以在以下catch-22中,
- 我可以手动调用
nuget pack。 href =“ https://stackoverflow.com/q/60249952/1303323”>可怕的NU5128 错误。所选答案建议简单地忽略错误。我很高兴这样做,但是在本地发布包装之后,我注意到不包括依赖项。尽管我添加了一种依赖json.net的依赖性,但为了测试。如果我配置
yml
创建软件包,则在Appveyor中出现同样的错误。
- 我可以通过设置
generatePackageOnbuild
将.csproj文件中的所有相关属性指定为true。它有效并采取依赖关系正确,但是我无法像 nuspec的替换令牌。即使我在assemblyInfo.cs
中将其更改为1.2.3.4
,该版本默认为1.0.0.0
。
注释
- 此答案表明NUSPEC和CSPROJ配置可以共存,并且已合并。这个问题是从2013年开始,所以我猜测不是指SDK项目。不幸的是,对我而言并非如此。
- 我尝试在csproj中添加
< nuspecfile>
47398907/1303323“>在这里。可能是因为这指示Nuget在NUSPEC上运行Pack,而不是在CSPROJ上运行并合并NUSPEC。我无法确定,因为将构建的冗长设置为详细的
无助于了解Nuget Pack尝试做什么。 - 在msbuild中获取
汇编信息>
,然后将其直接使用到<版本>
属性并不像一个人想象的那样简单,它也以$版本$
的目的而击败了目的。
汇编信息如果存在,则否则会汇编
可以通过和
.nuspec
带有$ $版本$
修补修补程序并获得依赖项在NUSPEC中吧?
What I've been strugling with for some time:
I have a "traditional" (i.e. non-SDK) csproj file. I want to create a nuget package. That's easy but devil hides in the details and I end up in the following catch-22
- I can manually call
nuget pack .\Foo.csproj
, with or without a nuspec file, but then I get the dreaded NU5128 error. The chosen answer suggests to simply ignore the error. I would happily do that, but after publishing the package locally, I noticed that the dependencies are not included. Though there is one dependency to JSON.net that I added for the sake of testing. The same error appears in AppVeyor if I configure myyml
to create the package.
- I can specify all the packaging related properties in the .csproj file by setting
GeneratePackageOnBuild
to true. It works and takes the dependencies right but then I can't patch the version like I could do with the replacement tokens of nuspec. The version defaults to1.0.0.0
even if I change it in theAssemblyInfo.cs
to1.2.3.4
.
Notes
- This answer suggests that nuspec and csproj configuration can coexist and they are merged. The question is from 2013 so I guess it's not referring to SDK projects. Unfortunately that's not the case for me.
- I tried adding a
<NuspecFile>
in the csproj but then it seems that replacement tokens don't work and I get the error described here. Probably because this instructed nuget to run pack on the nuspec instead of running it on csproj and merge the nuspec. I can't know for sure though as setting the build verbosity toDetailed
didn't help to understand what nuget pack tried to do. - Getting the
AssemblyInformationalVersion
in msbuild and use it straight to the<Version>
property isn't as straightforward as one might think and it also defeats the purpose as$version$
is doing exactly that according to the documentation:
AssemblyInformationalVersion if present, otherwise AssemblyVersion
Is there a way to really "merge" .csproj
and .nuspec
with $version$
patching and get the dependencies in the nuspec right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
到目前为止,最好的行动是将项目转换为SDK格式。它有几个优势。更少的配置,不需要
.nuspec
文件,无需assemblyInfo.cs
或predition> versionInfo.cs
files,.nupkg 依赖项是正确的,Appveyor可以直接修补
.csproj
file 如果这是一个SDK项目文件。如果要保持遗产格式,则不是解决方案本身,但它可以使您使用CI/CD,而不是让您使用工具进行战斗。
So far the best course of action was to convert the project to SDK format. It has several advantages. Less configuration, no need for
.nuspec
file, no need forAssemblyInfo.cs
orVersionInfo.cs
files,.nupkg
dependencies are correct and AppVeyor can patch directly the.csproj
file if it's an SDK project file.Not a solution per se if one wants to keep the legacy format, but it gets you going with the CI/CD instead of having you fighting with tools.