简体   繁体   English

Nuget Pack不包括新文件

[英]Nuget Pack not including new files

I've added new models and helpers to my project, but when I run nuget pack and install the package in my project I don't see the new items in the Assembly Explorer nor can I use them. 我已经在项目中添加了新的模型和助手,但是当我运行nuget pack并将其安装到项目中时,我在Assembly Explorer中看不到新项目,也无法使用它们。 Am I missing something during the build that wouldn't include new files added to the package? 我在构建过程中丢失了一些不包括添加到软件包中的新文件的东西吗?

I'm using visual studio 2017 and the nuget cli 我正在使用Visual Studio 2017和nuget cli

At a guess, you didn't change the package version when you changed the code and packed again. 猜测,更改代码并再次打包时,您没有更改软件包版本。 NuGet is designed such that the package id/version produces an immutable package. NuGet的设计目的是使程序包ID /版本生成不可变的程序包。 This means it's valid to download a package, say Newtonsoft.Json 12.0.1 from nuget.org just once, and every time you use that package in any project on the same computer you can re-use the same download, rather than having to download it every time you restore/build the project. 这意味着从nuget.org下载Newtonsoft.Json 12.0.1这样的软件包只需一次,并且每次在同一计算机上的任何项目中使用该软件包时,您都可以重复使用相同的下载内容,而不必每次还原/构建项目时都下载它。

This causes some people problems when they're trying to test their packages. 这会在某些人尝试测试其软件包时引起一些问题。 One option is to take advantage of Semantic Versioning and use 1.0.1-preview.1 , 1.0.1-preview.2 , so every single build of the project has a unique version number. 一种选择是利用语义版本控制,并使用1.0.1-preview.1 1.0.1-preview.2 ,因此项目的每个构建版本都有唯一的版本号。 In addition, or instead, you could use a nuget.config to set the globalPackagesFolder to a different location that gets cleared every time you change the package. 另外,或者相反,您可以使用nuget.configglobalPackagesFolder设置为其他位置,该位置在每次更改软件包时都会清除。 If you delete the "cache", it can't reuse the old contents. 如果删除“缓存”,则无法重复使用旧内容。 But this only works if you control the machines that use the package. 但这仅在您控制使用该软件包的计算机时有效。 Once you publish the package where anyone else can use the package, you will cause problems if you change the contents, which is why nuget.org doesn't allow deleting packages, only unlisting them. 一旦发布了该软件包,其他任何人都可以使用该软件包,那么如果更改内容,将会导致问题,这就是nuget.org不允许删除软件包而仅取消列出它们的原因。

However, another possible solution is to just not use packages and simply use project references. 但是,另一种可能的解决方案是不使用包,而仅使用项目引用。 Some people have the misconception that if you have two packages, one depends on the other, that they need to use package references to make sure NuGet dependency information flows. 有些人会误认为,如果您有两个软件包,则一个依赖另一个软件包,他们需要使用软件包引用来确保NuGet依赖项信息流。 That's not correct. 那是不对的。 If you pack with the MSBuild pack targets (highly recommended, and the default option for SDK style projects), NuGet will always convert project references into NuGet dependencies. 如果打包了MSBuild打包目标(强烈建议使用,并且是SDK样式项目的默认选项),则NuGet始终会将项目引用转换为NuGet依赖项。 nuget pack will convert project references into dependencies when the other project also has its own nuspec file. 当另一个项目也有自己的nuspec文件时, nuget pack会将项目引用转换为依赖nuspec When you test your project with project references, you never have to worry about immutable packages. 使用项目引用测试项目时,您不必担心不可变的程序包。 Just pack when it's ready, but it's not needed for testing. 准备好后就打包,但测试不需要。

也许您需要编辑.nuspec文件(与.csproj处于同一级别)以包含新文件?

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM