NuGet Uninstall.ps1 - remove a project reference

前端 未结 2 609
栀梦
栀梦 2021-02-09 14:44

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

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


        
2条回答
  •  攒了一身酷
    2021-02-09 15:35

    There are some casting issues to do this in powershell.

    this is the c# to remove a reference.

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

    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
    

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

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

提交回复
热议问题