NuGet Uninstall.ps1 - 删除项目引用 [英] NuGet Uninstall.ps1 - remove a project reference

查看:38
本文介绍了NuGet Uninstall.ps1 - 删除项目引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

So in my Install.ps1 I can add a reference like this:

param($installPath, $toolsPath, $package, $project)
$project.Object.References.Add("YourDLL")

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

How do you remove a project reference in PowerShell?

推荐答案

在 powershell 中执行此操作存在一些强制转换问题.

There are some casting issues to do this in powershell.

这是删除引用的 c#.

this is the c# to remove a reference.

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();
        }

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

If you want to use the Solution Factory nuget package you can use the powershell command that solution factory adds.

Remove-LibraryReference  projectName system.web

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

Here is a link the the solution factory source http://solutionfactory.codeplex.com/SourceControl/network/Forks/erichexter/PowershellRewrite

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

Update: new url for solution factory: https://github.com/erichexter/SolutionFactory

这篇关于NuGet Uninstall.ps1 - 删除项目引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆