nuget - 创建 NuGet 包,用于安装将 Copy Local 设置为 false 的引用

标签 nuget

有没有办法创建一个 NuGet 包,当该包安装到项目中时,它会添加对 dll 的引用,并将“本地复制”设置为 false?

我假设它是“install.ps1”文件中的某种脚本。

最佳答案

是的,正如您所猜测的,您可以使用 install.ps1 执行此操作。

这是一个示例 install.ps1,它会在您每次运行 System.dll 时翻转 System.dll 上的标志。使用此示例,您应该能够了解如何做您想做的事:

param($installPath, $toolsPath, $package, $project)

foreach ($reference in $project.Object.References)
{
    if($reference.Name -eq "System")
    {
        if($reference.CopyLocal -eq $true)
        {
            $reference.CopyLocal = $false;
        }
        else
        {
            $reference.CopyLocal = $true;
        }
    }
}

但是这个 MSDN 文档应该会有所帮助。
  • Object Hanselman 使用解析到 VSProject Interface.
  • $project变量 NuGet 为您提供对 Project Interface. 的解析
  • 关于nuget - 创建 NuGet 包,用于安装将 Copy Local 设置为 false 的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11105286/

    相关文章:

    nuget - nuget.config 的文档?

    visual-studio - 无需 NuGet 即可恢复 NuGet 包恢复同意

    c# - 系统.MissingMethodException : Method not found?

    command-line - nuget pack 引发未设置为对象实例的对象引用。异常(exception)

    .net-core - dotnet tool install -g 无法解析

    .net - nuget没有添加引用

    .net - 将解决方案更新到.net Framework 4.7 : issue with Roslyn

    c# - 将 .NetStandard 2.0 Nuget 包安装到 VS2015 Net 4.6.1 项目中

    visual-studio - 在没有 NuGet 的情况下在 Visual Studio 上安装测试运行器

    c# - 无法安装 nuget 包 unity 2