Modifying Visual Studio solution and project files with PowerShell

前端 未结 1 1426
盖世英雄少女心
盖世英雄少女心 2021-02-09 04:03

We are currently reorganizing our source code, moving stuff around in a new directory structure. This impacts our Visual Studio solution and project files, where things like ass

1条回答
  •  终归单人心
    2021-02-09 05:01

    In my experience, the easiest way to manipulate Visual Studio solutions using PowerShell (from within or outside of Visual Studio) is to load the project file as XML and use PowerShell to manipulate it.

    $proj = [xml](get-content Path\To\MyProject.csproj)
    $proj.GetElementsByTagName("PostBuildEvent") | foreach {
        $_."#text" = 'echo "Hello, World!"'
    }
    $proj.Save("Path\To\MyProject.csproj")
    

    If you're running your script in the NuGet Package Manager Console, you can get the paths to all of the project files like so:

    PM> get-project -all | select -expand FileName
    C:\Users\Me\Documents\Visual Studio 10\Projects\MyProject\MyProject.csproj
    C:\Users\Me\Documents\Visual Studio 10\Projects\MyProject\MyProjectTests.csproj
    PM>
    

    0 讨论(0)
提交回复
热议问题