Nuget PowerShell script to modify Global.asax.cs

后端 未结 4 1925
一生所求
一生所求 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:38

    Here's the answer in case someone needs it, this goes in your Install.ps1 inside the Tools folder:

    param($installPath, $toolsPath, $package, $project)
    
    # Read the transformed text from the custom template included in the package
    $customGlobalAsax = $project.ProjectItems | where { $_.Name -eq "Global.asax.cs.custom" }
    $customGlobalAsax.Open()
    $customGlobalAsax.Document.Activate()
    $customGlobalAsax.Document.Selection.SelectAll(); 
    $replacementGlobalAsax = $customGlobalAsax.Document.Selection.Text;
    $customGlobalAsax.Delete()
    
    # Replace the contents of Global.asax.cs
    $globalAsax = $project.ProjectItems | ForEach-Object { $_.ProjectItems } | where { $_.Name -eq "Global.asax.cs" }
    if($globalAsax) {
        $globalAsax.Open()
        $globalAsax.Document.Activate()
        $globalAsax.Document.Selection.SelectAll()
        $globalAsax.Document.Selection.Insert($replacementGlobalAsax)
        $globalAsax.Document.Selection.StartOfDocument()
        $globalAsax.Document.Close(0)
    }
    

提交回复
热议问题