使用msbuild进行构建并动态设置项目引用 [英] Build with msbuild and dynamically set project references

查看:99
本文介绍了使用msbuild进行构建并动态设置项目引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个引用SQL Server程序集的项目.使用SQL Server 2005和SQL Server 2008,我目前正在维护2个项目文件,这些文件指向相同的源文件,唯一的区别是对SQL Server程序集的引用.

I have a couple of projects which reference SQL Server assemblies. With SQL Server 2005 and SQL Server 2008 I am currently maintaining 2 project files which point to the same source files and the only difference is the references to the SQL Server assemblies.

是否有某种方式只能维护一个项目并在构建脚本中动态指定引用?

Is there some way that I can only maintain one project and dynamically specify the references in my build script?

推荐答案

在寻找与您遇到的相同问题的解决方案时,我想到了在ItemGroup上添加条件的建议解决方案.但这有副作用,因为在Visual Studio引用中我可以看到两个引用,这也影响了ReSharper.

Searching for a solution to the same problem you had I came to the proposed solution of having a Condition on the ItemGroup. But this had a side effect because in Visual Studio references I could see both references, which also impacted ReSharper.

我终于使用了否则时选择",并且ReSharper和Visual Studio显示两个引用时,我再也没有任何问题了.

I finally use a Choose When Otherwise and I don't have any issue anymore with ReSharper and Visual Studio showing two References.

<Choose>
  <When Condition=" '$(Configuration)' == 'client1DeployClickOnce' ">
    <ItemGroup>
        <ProjectReferenceInclude="..\client1\app.Controls\app.Controls.csproj">
        <Project>{A7714633-66D7-4099-A255-5A911DB7BED8}</Project>
        <Name>app.Controls %28Sources\client1\app.Controls%29</Name>
      </ProjectReference>
    </ItemGroup>
  </When>
  <Otherwise>
    <ItemGroup>
      <ProjectReference Include="..\app.Controls\app.Controls.csproj">
        <Project>{2E6D4065-E042-44B9-A569-FA1C36F1BDCE}</Project>
        <Name>app.Controls %28Sources\app.Controls%29</Name>
      </ProjectReference>
    </ItemGroup>
  </Otherwise>
</Choose>

这篇关于使用msbuild进行构建并动态设置项目引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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