将多个引用分组到一个标记元素中

发布于 2024-12-01 16:47:58 字数 672 浏览 0 评论 0原文

我们正在使用一些第三方库,它们具有一些必须从项目中引用的依赖项。

因此,每个“csproj”文件都会有一堆始终相同的“Reference”元素。

有没有一种方法可以将这组元素分组到一个标准元素中,以便在所有 csproj 文件中使用?

例如:

<ABunchOfReferences>
    <Reference Include="Reference1" />
    <Reference Include="Reference2" />
    <Reference Include="Reference3" />
</ABunchOfReferences>
...
<ItemGroup>
    <ABunchOfReferences/>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    ...
</ItemGroup>

“ABunchOfReferences”将是一种全局定义的宏,并由所有 csprojs 包含,使用时将扩展为 3 个“Reference”元素。

预先感谢您的任何想法。

we are using some third-party library that have some dependencies that must be referenced from the projects.

So each "csproj" file will have a bunch of "Reference" elements that will always be identical.

Is there a way to group this set of elements in one standard element that could be used accross all the csproj files ?

E.g :

<ABunchOfReferences>
    <Reference Include="Reference1" />
    <Reference Include="Reference2" />
    <Reference Include="Reference3" />
</ABunchOfReferences>
...
<ItemGroup>
    <ABunchOfReferences/>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    ...
</ItemGroup>

"ABunchOfReferences" would be a kind of macro globally defined and included by all the csprojs that when used would be expanded as 3 "Reference" elements.

Thanks in advance for any idea.

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

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

发布评论

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

评论(2

秉烛思 2024-12-08 16:47:58

您可以在导入文件中设置引用,然后有选择地将它们包含在主文件中,

在 References.props 中

<ItemGroup>
   <BunchOfReferences Include="Reference1" /> 
   <BunchOfReferences Include="Reference2" /> 
   <BunchOfReferences Include="Reference3" /> 
</ItemGroup>
<ItemGroup>
   <MoreReferences Include="MoreReference1" /> 
   <MoreReferences Include="MoreReference2" /> 
   <MoreReferences Include="MoreReference3" /> 
</ItemGroup>

...然后在单个项目文件中

<Import Project="PathTo\References.props" />

<ItemGroup>
   <Reference Include="System" />
   <References Include="@(BunchOfReferences)" />
   <References Include="@(MoreReferences)" />
</ItemGroup>

You can set up your references in an import file, then selectively include them in the main file,

In References.props

<ItemGroup>
   <BunchOfReferences Include="Reference1" /> 
   <BunchOfReferences Include="Reference2" /> 
   <BunchOfReferences Include="Reference3" /> 
</ItemGroup>
<ItemGroup>
   <MoreReferences Include="MoreReference1" /> 
   <MoreReferences Include="MoreReference2" /> 
   <MoreReferences Include="MoreReference3" /> 
</ItemGroup>

...then in the individual project file

<Import Project="PathTo\References.props" />

<ItemGroup>
   <Reference Include="System" />
   <References Include="@(BunchOfReferences)" />
   <References Include="@(MoreReferences)" />
</ItemGroup>
め七分饶幸 2024-12-08 16:47:58

您可以将所有“ABunchOfReferences”放在一个单独的文件中,然后将该文件包含在您的 ItemGroup 中,如下所示:

<ItemGroup>
    <Import Project="PathToFile\yourBunchofReferenceFile" />
    <Reference Include="System" />
 ...
</ItemGroup>

You can put all your "ABunchOfReferences" in a separate file and then include that file inside your ItemGroup like this:

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