Nuget PowerShell script to modify Global.asax.cs

后端 未结 4 1906
一生所求
一生所求 2021-01-06 01:22

I\'m building a nuget package for my company MVC4 template. I have run into an issue where I need the Global.asax.cs to be modified to add these two lines:

4条回答
  •  既然无缘
    2021-01-06 01:47

    If you want to "replace" some text in some file you can do like this:

    $file = $project.ProjectItems | ForEach-Object { $_.ProjectItems } | where { $_.Name -eq "Global.asax.cs" }
    if($file) {
        $file.Open()
        $file.Document.Activate()
        $file.Document.Selection.StartOfDocument()
        $file.Document.ReplaceText("TextToFind`n", "TextToReplace")
    }
    

    Note the `n which is escaping for \n or enter (CR).

    If you need quote character " it can be escaped as `" as well

提交回复
热议问题