简体   繁体   中英

How to include an <ItemGroup> across multiple .csproj files

Within Visual Studio (2019 in this case) solution, is there a way to specify an <ItemGroup> in a location that multiple.csproj files can use it within the solution?

As an example, this ItemGroup is used in multiple.csproj files within Test.sln. Instead of having to add this ItemGroup to each.csproj file, I'd like to somehow place it in a common file and reference it from the.csproj file. Is that possible?

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="3.1.10" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNETTestSdk)" />
  </ItemGroup>

You can use a Directory.Build.props file in the directory hierarchy (eg next to the.sln file) containing only these common things:

<Project>
  <ItemGroup>
    ...
  </ItemGroup>
</Project>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM