Update: This has been made easier with 2.2 Tooling. Make sure that your dotnet --version SDK version is at least 2.2.100, even when buidling 2.1 applications
Just add a versionless package reference to your project while keeping the Microsoft.NET.Sdk:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<!-- other references to xunit, test SDK etc. -->
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AspNetCoreAppToTest\AspNetCoreAppToTest.csproj" />
</ItemGroup>
</Project>
Original:
ASP.NET Core 2.1 uses a new “shared framework” to run ASP.NET Core applications on. Test projects need to be modified/updated to also use this shared framework using one of the following approaches:
-
Change the test project’s
<Project>tag in the first line to use the web SDK (Microsoft.NET.Sdk.Webinstead ofMicrosoft.NET.Sdk) and add a package reference toMicrosoft.AspNetCore.App(or.Allif you are using that inside the web project) without specifying a versionThe project file (.csproj) of the test project should now look like this:
<Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>netcoreapp2.1</TargetFramework> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="2.1.1" /> <PackageReference Include="Microsoft.AspNetCore.App" /> <!-- other references to xunit, test SDK etc. --> </ItemGroup> <ItemGroup> <ProjectReference Include="..\AspNetCoreAppToTest\AspNetCoreAppToTest.csproj" /> </ItemGroup> </Project> -
Alternative: Leave the
Sdkas-is and add aPackageReferenceto the shared framework package but specify a version.This can be done by simply adding a NuGet reference to
Microsoft.AspNetCore.App. However, this may cause issues since the SDK may choose to update the reference when a new patch release of the ASP.NET Core is released and the tooling is updated to reflect this. You will need update the NuGet reference for every patch release.