简体   繁体   中英

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. When I use the Visual Studio package manager cli or interface files get added to the solution. 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.

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.

nuspec file for package:

    <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. 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 ; 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 :

在此处输入图片说明

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.

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

So, that the reason why you have different behavior for Package Manager Console and Nuget.exe.

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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