msbuild一个项目,该项目引用具有不同配置的项目 [英] msbuild a project referencing projects with different configurations

查看:83
本文介绍了msbuild一个项目,该项目引用具有不同配置的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些Visual Studio项目,这些项目依赖于其他项目,这些项目具有不同的配置.

i have some visual studio projects which depend on other projects, which have different configurations.

example:
Project MyProject (Configuration: Release)
  References:
    Project LibA (Configuration: Release_DontLink)
    Project LibB (Configuration: Release

由于要用于不同项目的配置存储在解决方案文件中,因此使用Visual Studio进行构建可以正常工作.

Building using Visual Studio works correctly as the Configurations to be used for the different projects are stored inside the solution file.

但是当我使用msbuild构建MyProject时,它会构建LibA的Release配置,这是不正确的.由于LibA和LibB都被其他许多项目使用,因此我无法更改这些配置,因此只能控制MyProject.

But when i use msbuild to build MyProject, it builds the Release configuration of LibA, which is incorrect. Since both LibA and LibB are used by numerous other Projects, i cant change those configurations, i only have control over MyProject.

是否可以在不更改LibA和LibB项目的情况下使用MsBuild构建MyProject?

Is there any way to build MyProject using MsBuild without changing the LibA and LibB projects?

可能相关的问题:在MSBuild中配置ProjectReference ,但是我没有完全完成了解答案,我认为这需要我更改LibA/LibB

Possibly related question: Configuration for ProjectReference in MSBuild, however i did not fully understand the answer, and i think it would require me to change LibA/LibB

推荐答案

在解决方案级别(即MyProject.sln)上,打开属性页并设置Release配置,以为项目Release_DontLink配置>.如果您无法控制sln文件,则应该可以创建该文件的副本(即MyProject.Release.sln).

On the solution level (i.e: MyProject.sln), open the property pages and set the Release configuration to build Release_DontLink configuration for project LibA. If you don't have control over the sln file, you should be able to create a copy of it (i.e: MyProject.Release.sln).

然后使用以下方法构建解决方案:

Then build the solution with:

msbuild MyProject.sln /p:Configuration=Release

或者,在覆盖OutDir属性的同时构建MyProject构建LibA之后,(甚至不是最佳实践):

Alternatively (not even remotely a best practice), after building MyProject build LibA while overriding its OutDir property:

msbuild LibA.csproj /p:Configuration=Release_DontLink;OutDir=..LibA\Release

这篇关于msbuild一个项目,该项目引用具有不同配置的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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