Modify .csproj Files Programmatically

I have the source code of Entlib 5.0, and I need to sign all assemblies using my own key (snk file).

The easiest way is to open the EnterpriseLibrary.2010 solution file in Visual Studio 2010 , and for each project, select Properties-> Sign , then select Sign assembly and finally select your key file.

But I do not want to do this manually, then I could write a script to manually edit the project files and paste the following at the end of the current PropertyGroups list:

 <PropertyGroup> <SignAssembly>true</SignAssembly> </PropertyGroup> <PropertyGroup> <AssemblyOriginatorKeyFile>keyFile.snk</AssemblyOriginatorKeyFile> </PropertyGroup> 

Any helper class in C # or scripts, if it would be better to do this in a simple and quick way?

+7
source share
1 answer

You can take a look at the Microsoft.Build.BuildEngine namespace MSDN link

Code example:

 Engine eng = new Engine() Project proj = new Project(eng); proj.Load(FullProjectPath); proj.SetProperty("SignAssembly", "true"); proj.Save(FullProjectPath); 

I recently used something similar to make a series of changes to all of my company .csproj files (over 200) instead of manually opening each project and making changes.

Hope this helps.

+21
source

All Articles