简体   繁体   English

包管理器控制台与 Nuget.exe 构建文件行为

[英]Package Manager Console vs Nuget.exe build file behavior

I have a .net 4.71 classic project to which I am trying to add nuget package I generated.我有一个 .net 4.71 经典项目,我正在尝试向其中添加我生成的 nuget 包。 When I use the Visual Studio package manager cli or interface files get added to the solution.当我使用 Visual Studio 包管理器时,cli 或接口文件被添加到解决方案中。 When I add the package via nuget.exe (4.5.1.4879) those files behave as intended and are not added to the solution, but are only output on build.当我通过 nuget.exe (4.5.1.4879) 添加包时,这些文件按预期运行,不会添加到解决方案中,而只会在构建时输出。

What might be causing this and How can I prevent this behavior?什么可能导致这种情况以及如何防止这种行为?

It is the .post-build folder and the *.targets which get added to the solution when using Update-Package or the UI.使用 Update-Package 或 UI 时,将 .post-build 文件夹和 *.targets 添加到解决方案中。

nuspec file for package:包的 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>

What might be causing this and How can I prevent this behavior?什么可能导致这种情况以及如何防止这种行为?

That because Package Manager Console and Nuget.exe have different behavior when you install nuget package.那是因为安装 nuget 包时包管理器控制台和Nuget.exe有不同的行为。 I am afraid you can not prevent this behavior.恐怕你无法阻止这种行为。

When you use nuget.exe to install the package, NuGet CLI does not modify a project file or packages.config ;使用 nuget.exe 安装包时, NuGet CLI 不会修改项目文件或 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 .通过这种方式,它类似于恢复,因为它只将包添加到磁盘,但不会更改项目的依赖项 See NuGet CLI reference :请参阅NuGet CLI 参考

在此处输入图片说明

Conversely, operation Install packages on Package Manager:相反,在包管理器上操作安装包:

Installs a package and its dependencies into a project.将包及其依赖项安装到项目中。

在此处输入图片说明

Besides, we could not use the Package manager console powershell outside visual studio, because package manager console is providing is access to visual studio objects.此外,我们无法在 Visual Studio 之外使用包管理器控制台 powershell,因为包管理器控制台提供对 Visual Studio 对象的访问。

https://github.com/NuGet/Home/issues/1512 https://github.com/NuGet/Home/issues/1512

So, that the reason why you have different behavior for Package Manager Console and Nuget.exe.所以,这就是为什么包管理器控制台和 Nuget.exe 有不同行为的原因。

Hope this helps.希望这可以帮助。

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

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