序列化和反序列化Visual Studio解决方案文件 - 或以编程方式编辑? [英] Serialize and Deserialize Visual Studio Solution files - or programmatically edit?

查看:203
本文介绍了序列化和反序列化Visual Studio解决方案文件 - 或以编程方式编辑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以编程方式添加和删除项目,解决方案,文件夹和其他项目,如资源文件的解决方案,但我不能完全肯定这将是一起去的最佳途径。

I wanted to programmatically add and remove projects, solution folders and other items such as resource files to a solution, but I'm not exactly sure what would be the best way to go with that.

对于那些不知道,高度简化的;这是一个sulution文件(的.sln)如何正常是这样的:

For those that don't know, highly simplified; this is how a sulution file (.sln) normally looks like:

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "project name", "projectpath\name.csproj", "{785ECC80-AF1B-4FBC-B97B-2EC43B7E81E8}"
EndProject
Global
    GlobalSection(ProjectConfigurationPlatforms) = postSolution
        {785ECC80-AF1B-4FBC-B97B-2EC43B7E81E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    EndGlobalSection
EndGlobal

我不知道这是否是一个实际的开放标准(如XML)(是),但它种好像在Visual Basic球队做出了自己的XML版本。 (不是恭维)

I'm not sure if this is an actual open standard such as xml (it is?), but it kind of seems like the visual basic team made its own version of xml. (not a compliment)

所以无论如何,这将是序列化和反序列化这和对象的最佳方式?我在想我自己能做IFormatter,但似乎相当复杂的。

So anyway, what would be the best way to serialize and deserialize this to and from objects? I was thinking about making my own IFormatter, but that seems rather complex.

推荐答案

根据 MSDN EnvDTE是一个包含Visual Studio的核心自动化对象和成员装配包裹的COM库。您还可以找到那里的 解决方案 和的 项目 使用实例接口应该是非常有帮助的。

Using EnvDTE library:

According to MSDN EnvDTE is an assembly-wrapped COM library containing the objects and members for Visual Studio core automation. You can also find there documentation of Solution and Project interfaces with using examples which should be very helpful.

解决方案文件:

似乎没有很多在这里做 - 增加一个项目,并设置构建配置。在我看来,最好的办法是使用简单的TextReader分析它,并添加一些数据后重写。这是模板。

It seems there isn't a lot to do here - adding a project and setting build configuration. In my opinion the best approach would be to parse it using simple TextReader and rewrite it after adding some data. This is the template.

项目({解决GUID})=项目名称,projectpath\\\
ame.csproj {项目GUID}

记住使用在每个项目的GUID相同的解决方案。

Remember to use the same solution guid in every project.

项目文件:

在这里没有意外,它是可以创建/使用LINQ to XML标准修改XML文件。举例规格全,请访问: http://msdn.microsoft.com/en -us /库/ dd393574.aspx 。当然,
不要忘了使用解决方案文件的GUID喜欢同一个项目。

No surprises here, it is standard XML file which you can create/modify using LINQ to XML. Whole specification with examples is available here: http://msdn.microsoft.com/en-us/library/dd393574.aspx. Of course Don't forget to use the same project guid like in solution file.

我希望这会有所帮助。

这篇关于序列化和反序列化Visual Studio解决方案文件 - 或以编程方式编辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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