Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

xml - Modify .csproj files programmatically

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

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

But I don't want to manually do that then I could write a script to manually edit the project files and insert the following at the end of the current list of PropertyGroups:

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

Any helper class in C# or scripting if were better for do it easy and quick way?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

Sample code:

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 across all of my company's .csproj files (over 200) instead of manually opening each project and making changes.

Hope this helps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...