NuGet Command-line options for uninstalling/reinstalling packages for TFS/VS2013 and NuGet 3.4.3

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 07:33:16

问题


I modified a solution and deleted one of the .csproj files and instead packaged the .dlls into a NuGet package. Then I added the package to the two other .csproj files that reference the .dlls. All was good - it builds locally, but I can't get it to build on the build server. When I look at the code gotten out of TFS for the build I see that the packages.config for both projects have the correct reference to the NuGet package, but when I open the solution in VS the references have little yellow exclamation marks next to them because they're broken references. The only way I can get it to build is to open the NuGet CMI and execute Uninstall-package package-name and the Install-Package package-name. Then the references are good. When I look in the packages.config of the main project it contains the correct reference to the Package. So I've given up on getting TFS to correctly grab the package, but since Install-Package and Uninstall-Package are CMI commands only I can't automate that (or can I)? Does anyone know if a way that I could automate that to happen after the source is pulled from TFS but before the build?


回答1:


The yellow exclamation marks issue should be related to the reference path. When you download the source from TFS to another location, the system cannot find the references as the original reference path changed.

So, you need to reinstall the package, you can use the NuGet command line in the Package Manager Console:

Update-Package -reinstall



回答2:


since Install-Package and Uninstall-Package are CMI commands only I can't automate that (or can I)? Does anyone know if a way that I could automate that to happen after the source is pulled from TFS but before the build?

The simple answer is you can not automate that. You can use the command Install-Package and Uninstall-Package to reinstall the packages to your project in the Package Manager Console, but it seems impossible to automate that. Please forgive me for the lengthy explanation below.

First, we need to know the different the operation Install packages between NuGet CLI and Package Manager, although NuGet CLI and Package Manager both support the operation Install packages.

The operation Install packages on NuGet CLI:

Obviously, NuGet will not reinstall the references when you using the Install-packages operation on the NuGet CLI, just download the package to the packages folder. See NuGet CLI reference:

The install command does not modify a project file or packages.config; in this way it's similar to restore in that it only adds packages to disk but does not change a project's dependencies.

Conversely, operation Install packages on Package Manager:

Installs a package and its dependencies into a project.

If you want to automate that, you have to do this operations via NuGet CLI. Since Install package on NuGet CLI will not modify the reference of project, so we could not automate the operation install package to update the reference of the project.

Besides, we also do not recommend you automate that. Once you have automate that, NuGet execute the uninstall/install operations every time before you build the project. We only need to do an uninstall/install the operation after get the project from TFS. Even we do not need to do this operation if the references of the project are not broken after NuGet restore. So according to the reference of the project to determine whether or not to use an command:

Update-Package -reinstall

in the Package Manager Console should be the best choice.



来源:https://stackoverflow.com/questions/45684692/nuget-command-line-options-for-uninstalling-reinstalling-packages-for-tfs-vs2013

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!