NuGet Uninstall.ps1 - 删除项目引用

ric*_*ott 6 powershell nuget

所以在我的Install.ps1中,我可以像这样添加一个引用:

param($installPath, $toolsPath, $package, $project)
$project.Object.References.Add("YourDLL")
Run Code Online (Sandbox Code Playgroud)

如何在PowerShell中删除项目引用?

Ale*_*roß 14

这是我们用于Machine.Specifications的内容:

param($installPath, $toolsPath, $package, $project)
$project.Object.References | Where-Object { $_.Name -eq 'Machine.Specifications.TDNetRunner' } | ForEach-Object { $_.Remove() }
Run Code Online (Sandbox Code Playgroud)


Eri*_*ter 8

在PowerShell中有一些强制转换问题.

这是删除引用的c#.

DTE dte = (DTE)dteObject;
        var targetProject = (VSProject)dte.GetProject(target).Object;
        var refToRemove = targetProject.References.Cast<Reference>().Where(assembly => assembly.Name.EndsWith(library, System.StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
        if (refToRemove != null)
        {
            refToRemove.Remove();
        }
Run Code Online (Sandbox Code Playgroud)

如果要使用Solution Factory nuget包,可以使用解决方案工厂添加的powershell命令.

Remove-LibraryReference  projectName system.web
Run Code Online (Sandbox Code Playgroud)

这是解决方案工厂源代码的链接http://solutionfactory.codeplex.com/SourceControl/network/Forks/erichexter/PowershellRewrite

更新:解决方案工厂的新网址:https: //github.com/erichexter/SolutionFactory