【问题标题】:Package Manager Console vs Nuget.exe build file behavior包管理器控制台与 Nuget.exe 构建文件行为
【发布时间】:2019-01-23 14:07:39
【问题描述】:

我有一个 .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>

【问题讨论】:

    标签: visual-studio nuget nuget-package nuspec package-manager-console


    【解决方案1】:

    这可能是什么原因造成的,我该如何防止这种行为?

    那是因为包管理器控制台和Nuget.exe 在安装 nuget 包时具有不同的行为。恐怕您无法阻止这种行为。

    当您使用 nuget.exe 安装包时,NuGet CLI 不会修改项目文件或 packages.config;这种方式类似于restore,它只是将包添加到磁盘,但不会更改项目的依赖项。见NuGet CLI reference:

    反之,在包管理器上操作安装包:

    将包及其依赖项安装到项目中。

    此外,我们无法在 Visual Studio 之外使用包管理器控制台 powershell,因为包管理器控制台提供的是对 Visual Studio 对象的访问。

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

    所以,这就是包管理器控制台和 Nuget.exe 行为不同的原因。

    希望这会有所帮助。

    【讨论】:

    • 感谢您的回答;符合我的观察。使用 nuget.exe 的包管理命令 powershell cmdlet 也是如此吗?您是否还知道以下是如何相关的 - 1)包管理控制台 2)nuget CLI 3)dotnet CLI
    猜你喜欢
    • 2012-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多