安瑞API代码,独立分出来的一套,版本比较老了
1
llj
2 天以前 7728ec834b099dbc8ab644429444208edd8407e8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
param($installPath, $toolsPath, $package, $project)
 
# Visual Studio execution done via NuGet Package Manager
Function VSExecution($toolsPath, $project)
{
    
 
    $project.DTE.ExecuteCommand("File.SaveAll", [system.string]::Empty)
 
    # Get the msbuild version of the project and add the import
    $msbuild = [Microsoft.Build.Evaluation.ProjectCollection]::GlobalProjectCollection.GetLoadedProjects($project.FullName) | Select-Object -First 1
 
    # now remove our property that points to this package path, "WebGreaseLibPath"
    foreach ($property in $msbuild.Properties)
    {
        if ($property.Name -eq "WebGreaseLibPath")
        {
            $propertyToRemove = $property
        }
    }
 
    if ($propertyToRemove -ne $null)
    {
        $propertyToRemove.Project.RemoveProperty($propertyToRemove)
        $project.Save()
    }
 
    $project.DTE.ExecuteCommand("File.SaveAll", [system.string]::Empty)
}
 
# Command line execution done by any external tool (For example, NuGetUpdater)
# $project - parameter value is path to Project file in this case.
Function CommandLineExecution($toolsPath, $project)
{
    [Reflection.Assembly]::LoadWithPartialName("System.Xml")
    [Reflection.Assembly]::LoadWithPartialName("System.Xml.Linq")
 
 
    
    $projXDoc = [System.Xml.Linq.XDocument]::Load($project)
    $defaultNameSpace = $projXDoc.Root.GetDefaultNamespace()
    $xmlReader = $projXDoc.CreateReader()
    $namespaceManager = new-object System.Xml.XmlNamespaceManager($xmlReader.NameTable)
    $namespaceManager.AddNamespace("my", $defaultNameSpace.NamespaceName)
 
    $msnRfPackageElement = [System.Xml.XPath.Extensions]::XPathSelectElement($projXDoc.Root, "//my:WebGreaseLibPath", $namespaceManager)
    if($msnRfPackageElement -ne $null)
    {
        $msnRfPackageElement.Remove()
    }
    
    # save the project
    $projXDoc.Save($project)
}
 
IF ($project -is [system.string])
{
    CommandLineExecution $toolsPath $project
}
ELSE
{
    VSExecution $toolsPath $project
}