Created
September 28, 2017 20:21
-
-
Save ankitvijay/0d8003f244fb4e9bcd6cd91717f34eab to your computer and use it in GitHub Desktop.
Edit Csproj Progamatically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System.Linq; | |
using Microsoft.Build.Evaluation; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var projectList = new List<string>() | |
{ | |
// Your Project file paths | |
}; | |
foreach (var project in projectList) | |
{ | |
var projectCollection = new ProjectCollection(); | |
var proj = projectCollection.LoadProject(project); | |
// Select Debug configuration | |
var debugPropertyGroup = | |
proj.Xml.PropertyGroups.First( | |
e => e.Condition == " '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "); | |
debugPropertyGroup.SetProperty("TreatWarningsAsErrors", "true"); | |
debugPropertyGroup.SetProperty("RunCodeAnalysis", "true"); | |
// Select Release configuration | |
var releasePropertyGroup = | |
proj.Xml.PropertyGroups.First( | |
e => e.Condition == " '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "); | |
releasePropertyGroup.SetProperty("TreatWarningsAsErrors", "true"); | |
releasePropertyGroup.SetProperty("RunCodeAnalysis", "true"); | |
//Sign assembly with a with strong name key | |
proj.SetProperty("SignAssembly", "true"); | |
proj.SetProperty("AssemblyOriginatorKeyFile", "test.pfx"); | |
//Save | |
proj.Save(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment