How do I fix the nasty warning I'm getting when running .NET Core tests from a command line via dotnet test
?
The dotnet --version
returns back 3.1.101
.
$ dotnet test watch : Started C:\Program Files\dotnet\sdk\3.1.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets(151,5): warning NETSDK1080: A PackageReference to Microsoft.AspNetCore.App is not necessary when targeting .NET Core 3.0 or higher. If Microsoft.NET.Sdk.Web is used, the shared framework will be referenced automatically. Otherwise, the PackageReference should be replaced with a FrameworkReference. [C:\github\demo\Demo\SmartHome.API\SmartHome.API.csproj] C:\Program Files\dotnet\sdk\3.1.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets(151,5): warning NETSDK1080: A PackageReference to Microsoft.AspNetCore.App is not necessary when targeting .NET Core 3.0 or higher. If Microsoft.NET.Sdk.Web is used, the shared framework will be referenced automatically. Otherwise, the PackageReference should be replaced with a FrameworkReference. [C:\github\demo\Demo\SmartHome.API\SmartHome.API.csproj] Test run for C:\github\demo\Demo\SmartHome.API.Test\bin\Debug\netcoreapp3.1\SmartHome.API.Test.dll(.NETCoreApp,Version=v3.1) Microsoft (R) Test Execution Command Line Tool Version 16.3.0 Copyright (c) Microsoft Corporation. All rights reserved. Starting test execution, please wait... A total of 1 test files matched the specified pattern.
Here's what my SmartHome.API.Test.csproj
looks like.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.10.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="MongoDB.Driver" Version="2.10.1" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="coverlet.collector" Version="1.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SmartHome.API\SmartHome.API.csproj" />
<ProjectReference Include="..\SmartHome.Models\SmartHome.API.Models.csproj" />
</ItemGroup>
</Project>
And this is the SmartHome.API.csproj
which seems to be the source of the issue.
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentValidation" Version="8.6.1" />
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.8" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.1" />
<PackageReference Include="MongoDB.Driver" Version="2.10.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SmartHome.Models\SmartHome.API.Models.csproj" />
</ItemGroup>
</Project>
A function that can process an HTTP request.
Microsoft.AspNetCore.App. Provides a default set of APIs for building an ASP.NET Core application. This package requires the ASP.NET Core runtime. This runtime is installed by the . NET Core SDK, or can be acquired separately using installers available at https://aka.ms/dotnet-download.
NETSDK1079: The Microsoft.AspNetCore.All package is not supported when targeting .NET Core 3.0 or higher. 09/15/2021 2 minutes to read
C:\Program Files\dotnet\sdk\3.0.100\Sdks\Microsoft.NET.Sdk argets\ Microsoft.NET.Sdk.DefaultItems.targets (149,5): warning NETSDK1080: A PackageReference to Microsoft.AspNetCore.App is not necessary when targeting .NET Core 3.0 or higher. If Microsoft.NET.Sdk.Web is used, the shared framework will be referenced automatically.
All the features of ASP.NET Core 2.x and Entity Framework Core 2.x are included in the Microsoft.AspNetCore.App package. The default project templates targeting ASP.NET Core 2.x use this package. We recommend applications targeting ASP.NET Core 2.x and Entity Framework Core 2.x use the Microsoft.AspNetCore.App package.
Microsoft.AspNetCore.App was designed to prevent untested version combinations of related bits being used together in the same app. Applications that use the Microsoft.AspNetCore.App metapackage automatically take advantage of the ASP.NET Core shared framework.
Changing a package dependency from Microsoft.AspNetCore.App
(2.2.8) into a FrameworkReference
in the SmartHome.API.csproj
solved the problem for me at the cost of introducing a new one.
+ <ItemGroup>
+ <FrameworkReference Include="Microsoft.AspNetCore.App" />
+ </ItemGroup>
+
<ItemGroup>
<PackageReference Include="FluentValidation" Version="8.6.1" />
- <PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.8" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.1" />
<PackageReference Include="MongoDB.Driver" Version="2.10.1" />
</ItemGroup>
I started seeing a new warning:
C:\Program Files\dotnet\sdk\3.1.101\Sdks\Microsoft.NET.Sdk\targets\ Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(39,5): warning NETSDK1086: A FrameworkReference for 'Microsoft.AspNetCore.App' was included in the project. This is implicitly referenced by the .NET SDK and you do not typically need to reference it from your project. For more information, see https://aka.ms/sdkimplicitrefs
...so I ended up removing the "Microsoft.AspNetCore.App"
reference altogether. Now the build is warning-free!
i.e. the file looks like this:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentValidation" Version="8.6.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.1" />
<PackageReference Include="MongoDB.Driver" Version="2.10.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SmartHome.Models\SmartHome.API.Models.csproj" />
</ItemGroup>
</Project>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With