MSBuild:如何根据生成项目的名称有条件地导入 .csproj 文件中的另一个项目?
上下文:我有一个 .Net 标准 2.0 项目,例如 ProjectA,其中我使用
语句从目标文件导入项目。该解决方案有许多项目(ProjectA、ProjectB、ProjectC 和 ProjectD)。使用项目引用在项目 B 和项目 C 中引用项目 A。
问题是:如果构建/重建请求源自特定项目(例如 ProjectC),我想忽略此导入语句并正常构建 ProjectA。如果构建请求源自项目 B 或项目 A,我想包含此导入。我了解
可以有一个 “条件”
属性。但我如何实现这个想法呢?有什么建议吗?
Context: I have a .Net standard 2.0 project, say ProjectA in which I use an <Import Project="xxxx.targets" />
statement to import a project from a target file. This solution has many projects (ProjectA, ProjectB, ProjectC and ProjectD). Project A is referenced in Project B and Project C using project references.
Here is the problem: If the build/rebuild request originated from a specific project, say ProjectC, I want to ignore this import statement and build the ProjectA normally. If the build request is originated from Project B or from Project A, I want to include this import.I understand that <Import Project="xxxx.targets" />
can have a "Condition"
attribute. But how do I implement this idea? Are there any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果尚未构建引用的项目,则
ProjectReference
将导致构建该项目。不支持根据需要该项目的项目来更改引用项目的构建。如果可以的话,就会产生各种各样的问题。当从解决方案构建时,ProjectB 或 ProjectC 可能会触发构建 ProjectA,并且由于 ProjectA 将构建一次,因此将为其中一个项目“错误”构建它。对于给定的配置/平台,项目应该始终构建相同的。
但您可以创建新的单独配置。
例如:
Configuration
属性的值对Import
进行条件化。(但是,我怀疑您提出的问题并不是您真正想要解决的问题。)
The
ProjectReference
will cause a referenced project to be built if it is not already built. There is no support for changing the build of a referenced project based on the project that needs the project. And if you could that would create all sorts of issues. When building from the solution either ProjectB or ProjectC could trigger building ProjectA and, since ProjectA will be built once, it will be built 'incorrectly' for one of the projects.For a given configuration/platform a project should always build the same.
But you can create new separate configurations.
For example:
Import
based on the value of theConfiguration
property.(However, I suspect that the question you have asked is not really the issue you are trying to solve.)