开发者

Group multiple references in one markup element

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>
...
<It开发者_运维百科emGroup>
    <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.


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>


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜