Edit csproj Project file programatically

Posted by

In my current engagement, we have more than 80 projects in a solution (don’t ask me why :)). Recently, as per quality guidelines, we needed to make few changes to each project.
For example:  Treat warnings as errors, enable code analysis for each project, sign assembly etc.

I realized doing it manually can take me entire day so I spent few mins to create a small script in C# to save my time. Here is the code snippet:

Hope it helps save some time for some of you 🙂

Update: I have created a command line utility for the solution and added it to GitHub. This utility accepts different set arguments to based on operations required to be performed. Please refer to ReadMe.md in GitHub for more details.

Advertisements

2 comments

  1. Hi, I tried your code but it’s replacing $(configuration) to ‘debug’. Is there a way to avoid it.

    1. You can, just change line
      var debugPropertyGroup =
      proj.Xml.PropertyGroups.First(
      e => e.Condition == ” ‘$(Configuration)|$(Platform)’ == ‘Debug|AnyCPU’ “);
      Instead of Debug, provide your own conifguration

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.