以编程方式修改.csproj文件 [英] Modify .csproj files programmatically

查看:390
本文介绍了以编程方式修改.csproj文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Entlib 5.0的源代码,我需要使用自己的密钥(snk文件)对所有程序集进行签名.

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

最简单的方法是在Visual Studio 2010 中打开EnterpriseLibrary.2010解决方案文件,并为每个项目选择 Properties-> Signing ,然后选择 Sign程序集,最后选择您的密钥文件.

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.

但是我不想手动执行操作,那么我可以编写一个脚本来手动编辑项目文件,并将以下内容插入当前PropertyGroups列表的末尾:

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>

如果使用C#或脚本编写的帮助器类更简单,更快捷,那么更好吗?

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

推荐答案

您可以查看Microsoft.Build.BuildEngine命名空间MSDN链接

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

示例代码:

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

我最近使用类似的方法对我公司的所有.csproj文件(超过200个)进行了一系列更改,而不是手动打开每个项目并进行更改.

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.

希望这会有所帮助.

这篇关于以编程方式修改.csproj文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆