更新Visual Studio项目引用编程 [英] Updating Visual Studio project references programatically

查看:160
本文介绍了更新Visual Studio项目引用编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的Visual Studio解决方案以编程方式更新项目的参考。

I wish to programatically update the references in the projects in my Visual Studio solution.

我在我的解决方案大约15个项目,当我开发/调试我想引用指向解决方案中的项目。

I have roughly 15 projects in my solution and when I am developing/debugging I want the references to point to the projects within the solution.

由于我的释放过程的一部分,我有时需要做一个项目的副本,然后更新引用指向内置的dll在某个文件夹中。

As part of my release procedure I sometimes need to make a copy of one project and then update the references to point to built dlls in a certain folder.

我可以计算出项目文件的结构和引用如何在他们的工作,我想建立一个命令行工具来分析项目文件,并根据需要更改引用。

I can work out the structure of the project files and how references work within them and I am thinking of building a command line tool to parse the project files and change references as required.

我的问题是:
1.这听起来一个明智的做法
2.有这个人的经验和/或如何做他们处理开发和释放模式
之间切换 3,没有人有处理解析的Visual Studio项目文件的库。

My questions are:
1. Does this sound a sensible thing to do
2. Has anyone experience of this and/or how do they handle switching between developing and release modes
3. Does anyone have any libraries that deal with parsing Visual Studio project files.

澄清:

感谢您的答复。也许我要澄清,我想用这几个情况。

Thanks for the responses. Perhaps I should clarify a few situations where I wish to use this.

一)我的应用程序包含15个项目。我尽量保持该解决方案尽可能小的什么,我的工作,所以说我有5个项目在我的解决方案。我现在需要调试/开发没有解决,所以我加入这个项目的项目之一,但我必须: - 设置在原项目中引用指向项目引用,而不是编译的DLL - 改变中新加入的项目引用指向相应的项目引用

a) My application contain 15 projects. I try and keep the solution as small as possible for what I am working on, so say I have 5 projects in my solution. I now need to debug/develop one of the projects not in the solution so I add this project but I have to: - set the references in the original projects to point to project references rather than compiled dlls - change the references in the newly added project to point to the appropriate project references

我想我的工具自动做到这一点,只有这样,我知道所以这在present操纵项目文件

I would like my tool to do this automatically and the only way I know to so this at present is manipulating the project files

b)作为一个服务包构建过程我把其中一个项目的副本,进行必要的code的变化,并建立使用Visual Studio的一部分。要做到这一点,我不得不改变所有引用到编译的DLL

b) As part of a service pack build procedure I take a copy of one of the projects, make the necessary code changes and build using Visual Studio. To do this I have to change all the references to the compiled dlls

推荐答案

我想一个更好的办法,这将是对直接在项目文件中的引用使用条件块。然后,所有你需要做的MSBuild的释放建设,它会选择正确的引用中设置一个特定的标志。

I think a better approach to this would be to use Conditional blocks on your references inside the project file directly. Then all you need to do is set a particular flag during the msbuild for the "release" build and it will pick up the correct references.

例如

<ItemGroup Condition="'$(IsRelease)'=='True'">
  <Reference Include="..." />
</ItemGroup>
<ItemGroup Condition="'$(IsRelease)'!='True'">
  <Reference Include="..." />
</ItemGroup>

这篇关于更新Visual Studio项目引用编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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