[英]How to restore own nuget package in another solution
I have C# solution called commons
where I have my Model and some common stuff that will be used by other solutions. 我有一个称为
commons
C#解决方案 ,其中有我的模型以及一些将由其他解决方案使用的常见内容。
As a Post Build Event I create a nuget package and copy it to my local Nuget folder ("C:\\packages")
作为构建后的事件,我创建一个nuget包并将其复制到本地的Nuget
folder ("C:\\packages")
Post Build Event: 构建后事件:
"$(ProjectDir)nuget.exe" pack "$(ProjectDir)Commons.csproj" - IncludeReferencedProjects
xcopy Commons.1.0.0.nupkg c:\\packages /Y
Note : Version never changes.
注意 :版本永远不会改变。
That creates successfully my new nuget package. 这样就成功创建了我的新nuget包。
Then on the other solution I reference that package and I can see everything ok. 然后,在另一个解决方案上,我引用该程序包,然后一切正常。 I can access all my models and everything.
我可以访问所有模型和所有内容。
The problem I have is 我的问题是
if I make any change to my Common projects (eg add a new field to my model) this will not appear on my solution. 如果我对Common项目进行了任何更改(例如,向模型添加新字段),则该更改将不会出现在我的解决方案中。
What am I missing?? 我想念什么?
Make sure the folder has following structure 确保文件夹具有以下结构
packageName/version/[packageName].[version].nupkg v1: abc.common/1.0.0/abc.common.1.0.0.nupkg v2: abc.common/2.0.0/abc.common.2.0.0.nupkg
Make sure the newer package has higher version, not just on the folder structure but also the nuspec file. 确保较新的软件包具有更高的版本,不仅在文件夹结构上,而且在nuspec文件上。 You can rename .nupkg to zip file, and access the nuspec file.
您可以将.nupkg重命名为zip文件,然后访问nuspec文件。 Or use package explorer https://github.com/NuGetPackageExplorer/NuGetPackageExplorer
或使用套件浏览器https://github.com/NuGetPackageExplorer/NuGetPackageExplorer
VS will automatically show upgrade button if there new version published. 如果发布了新版本,VS将自动显示升级按钮。
if I make any change to my Common projects (eg add a new field to my model) this will not appear on my solution.
如果我对Common项目进行了任何更改(例如,向模型添加新字段),则该更改将不会出现在我的解决方案中。
Long story. 很长的故事。
To resolve this issue, you should make sure two points, re-pack the package and re-install the re-packed to the solution after change your Commons
project. 要解决此问题,您应该确保两点,在更改
Commons
项目后, 重新包装软件包并重新安装重新包装的解决方案 。
1. Re-pack the package: 1.重新包装包装:
After make some change to the Commons
projects, you should re-pack the nuget package. 对
Commons
项目进行一些更改后,应重新打包nuget软件包。 For your situation, you should rebuild the Commons
project to generate the new nuget package. 根据您的情况,您应该重建
Commons
项目以生成新的nuget包。
Besides, whether you need to change the version number depends on your own requirement, we recommend to change the version number before you want to publish a new nuget package. 此外,是否需要更改版本号取决于您自己的要求,建议您在发布新的nuget软件包之前更改版本号。
To accomplish this, modify the AssemblyVersion
in the AssemblyInfo.cs
file before you publish the new version nuget package. 要做到这一点,修改
AssemblyVersion
中AssemblyInfo.cs
文件在发布新版本的NuGet包之前。 For example, 例如,
[assembly: AssemblyVersion("1.0.0.1")]
After build, you will get the nuget package Commons.1.0.0.1.nupkg
in the bin
folder, you can use wildcard *
in your copy command to copy package to c:\\packages
: 构建完成后,您将在
bin
文件夹中获得nuget包Commons.1.0.0.1.nupkg
,您可以在copy命令中使用通配符*
将包复制到c:\\packages
:
xcopy.exe /y "$(ProjectDir)$(OutDir)Commons.*.nupkg" "c:\packages"
If you do not want to change the version, you do not need to do more things in the point. 如果您不想更改版本,则无需立即执行更多操作。
2. Re-install the re-packed to the solution: 2.重新安装重新包装的解决方案:
After re-pack the nuget package, you need to replace the old nuget package with the new one in the packages source. 重新打包nuget软件包后,需要在软件包源中用新的nuget软件包替换旧的nuget软件包。
Need to point out that the command Update-Package Commons -reinstall
will NOT re-install the new version package. 需要指出的是,命令
Update-Package Commons -reinstall
不会重新安装新版本的软件包。
Because when you use this command to re-install nuget package, nuget will check the packages folder if exists that package Commons.1.0.0.nupkg
, if it exists, nuget will not restore the nuget package, so nuget will not to re-download the new version package in the package source . 因为当您使用此命令重新安装nuget软件包时,nuget会检查packages文件夹(如果存在该软件包
Commons.1.0.0.nupkg
,如果存在,则nuget不会还原nuget软件包,因此nuget不会重新安装-从软件包源中下载新版本的软件包 。 So Nuget still re-install the old package. 因此,Nuget仍然重新安装了旧软件包。 That is the reason why you got the problem.
这就是您遇到问题的原因。
To resolve this issue, you need to delete the package in the packages folder , then execute the re-install command to re-install the package. 要解决此问题,您需要删除程序包文件夹中的程序包 ,然后执行re-install命令以重新安装程序包。 Or you can uninstall the package first, then re-install it.
或者,您可以先卸载软件包,然后重新安装。
One more things, if you then use a different version of the package, you can use update package directly to install the new version package, not need to pay attention to delete package/uninstall first. 还有一件事情,如果您随后使用其他版本的软件包,则可以直接使用更新软件包来安装新版本的软件包,而无需注意首先删除软件包/卸载。
Hope this is clear. 希望这很清楚。
So... after trying 1000 things I was able to figure it out. 因此,在尝试了1000件事之后,我得以弄清楚了。
The correct command is : nuget pack Commons.csproj -BasePath .\\ -IncludeReferencedProjects
正确的命令是:
nuget pack Commons.csproj -BasePath .\\ -IncludeReferencedProjects
So missing the basepath was basically all 所以缺少基本路径
Post Build Event for someone else 为其他人发布构建事件
"$(ProjectDir)nuget.exe" pack "$(ProjectDir)Commons.csproj" -BasePath "$(ProjectDir)-IncludeReferencedProjects
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.