仅在没有这样的项目时,如何将项目包含在项目组中?

发布于 2025-02-12 18:23:57 字数 749 浏览 1 评论 0原文

我正在尝试为MS与C ++环境实现一个简单的MSBUILD“插件”。它应该利用一些实用程序,然后将用某些语言写入的文本文件转换为c-sources。

我面临着如何在VS Project中已经存在具有相同名称的文件的情况下,如何将生成的C文件添加到C编译器的输入项目列表中。我正在尝试通过我的.targets文件中的以下行实现这一目标:

<ItemGroup>
  <ClCompile Include="%(MyCompiler.Outputs)" Condition="???" />
</ItemGroup>

但是我不确定如何构成条件零件以达到目标。我尝试过的任何条件都导致正在添加生成的文件,并发出警告:

C:\Program Files\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppBuild.targets(1091,5): warning MSB8027: Two or more files with the name of <FileName>.c will produce outputs to the same location. This can lead to an incorrect build result.  The files involved are <FileName>.c, <FileName>.c.

I'm trying to implement a simple MSBuild "plugin" for MS VS C++ environment. It should utilise some utility which, in turn, converts text files written on certain language into C-sources.

And I faced with trouble of how to add the generated C-files dynamically into the C-compiler's input items-list in case of files with the same name already exist in the VS project. I'm trying to achieve this via the following line in my .targets file:

<ItemGroup>
  <ClCompile Include="%(MyCompiler.Outputs)" Condition="???" />
</ItemGroup>

but I'm not sure, how to compose the conditional part to reach the goal. Any conditions I tried lead to that the generated files is being added and VS throws the warning:

C:\Program Files\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppBuild.targets(1091,5): warning MSB8027: Two or more files with the name of <FileName>.c will produce outputs to the same location. This can lead to an incorrect build result.  The files involved are <FileName>.c, <FileName>.c.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青衫儰鉨ミ守葔 2025-02-19 18:23:57

有一个排除属性,可以排除项目组本身,例如,

<ItemGroup>
  <ClCompile Include="%(MyCompiler.Outputs)" Exclude="@(ClCompile)" />
</ItemGroup>

include中的项目与dexp exclude中的项目匹配不会被添加到项目组中。

例如:
假设 @(clCompile)由“ AC; BC”和%(MyCompiler.Outputs)组成,由“ CC; AC”组成。上面的代码评估为

<ClCompile Include="C.c;A.c" Exclude="A.c;B.c" />

“ AC”将不会添加(并重复),因为它在排除集合中。 @(clCompile)的新值将为“ AC; BC; CC”。

There is a Exclude attribute and the ItemGroup itself can be excluded, e.g.

<ItemGroup>
  <ClCompile Include="%(MyCompiler.Outputs)" Exclude="@(ClCompile)" />
</ItemGroup>

An item in the Include that matches with an item in the Exclude will not be added to the ItemGroup.

As an example:
Assume @(ClCompile) consists of "A.c;B.c" and %(MyCompiler.Outputs) consists of "C.c;A.c". The code above evaluates to

<ClCompile Include="C.c;A.c" Exclude="A.c;B.c" />

"A.c" will not be added (and duplicated) because it is in the Exclude set. The new value of @(ClCompile) will be "A.c;B.c;C.c".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文