[英]Package Manager Console vs Nuget.exe build file behavior
我有一个 .net 4.71 经典项目,我正在尝试向其中添加我生成的 nuget 包。 当我使用 Visual Studio 包管理器时,cli 或接口文件被添加到解决方案中。 当我通过 nuget.exe (4.5.1.4879) 添加包时,这些文件按预期运行,不会添加到解决方案中,而只会在构建时输出。
什么可能导致这种情况以及如何防止这种行为?
使用 Update-Package 或 UI 时,将 .post-build 文件夹和 *.targets 添加到解决方案中。
包的 nuspec 文件:
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>idhere</id>
<version>0.1.0.0</version>
<authors>names here</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description></description>
</metadata>
<files>
<file src="bin/release/project.dll" target="lib\net461" />
<file src="bin/release/project.pdb" target="lib\net461" />
<file src="*.ps1" target="build" />
<file src=".post-build\*.*" target="build\.post-build" />
<file src="*.targets" target="build" />
<file src="**\*.cs" target="src" exclude="**\bin\**;**\obj**;**\Properties\**"/>
</files>
</package>
什么可能导致这种情况以及如何防止这种行为?
那是因为安装 nuget 包时包管理器控制台和Nuget.exe
有不同的行为。 恐怕你无法阻止这种行为。
使用 nuget.exe 安装包时, NuGet CLI 不会修改项目文件或 packages.config ; 通过这种方式,它类似于恢复,因为它只将包添加到磁盘,但不会更改项目的依赖项。 请参阅NuGet CLI 参考:
相反,在包管理器上操作安装包:
将包及其依赖项安装到项目中。
此外,我们无法在 Visual Studio 之外使用包管理器控制台 powershell,因为包管理器控制台提供对 Visual Studio 对象的访问。
https://github.com/NuGet/Home/issues/1512
所以,这就是为什么包管理器控制台和 Nuget.exe 有不同行为的原因。
希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.