Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting NETSDK1023 even when xunit.assert isn't implicitly referenced #13798

Closed
5 tasks
bricelam opened this issue Jun 12, 2023 · 9 comments
Closed
5 tasks

Getting NETSDK1023 even when xunit.assert isn't implicitly referenced #13798

bricelam opened this issue Jun 12, 2023 · 9 comments
Labels
area-Infrastructure-libraries Area maintained by .NET libraries team: APICompat, AsmDiff, GenAPI, GenFacades, PkgProj, etc

Comments

@bricelam
Copy link
Contributor

  • This issue is blocking
  • This issue is causing unreasonable pain

After a130eb4, we're seeing some unusual behavior in the EF Core specification tests (tests that ship as NuGet packages for providers to use).

We have these lines in our csproj:

<Project>
  <PropertyGroup>
    <IsUnitTestProject>False</IsUnitTestProject>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="xunit.assert" Version="$(XUnitVersion)" />
    <PackageReference Include="xunit.core" Version="$(XUnitVersion)" />
  </ItemGroup>
</Project>

The error messages that started showing up after the arcade commit are as follows:

D:\efcore.dotnet\sdk\8.0.100-preview.6.23279.4\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.Shared.targets(152,5): error NETSDK1023: A PackageReference for 'xunit.assert' was included in your project. This package 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 [D:\efcore\test\EFCore.Specification.Tests\EFCore.Specification.Tests.csproj]
D:\efcore.dotnet\sdk\8.0.100-preview.6.23279.4\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.Shared.targets(152,5): error NETSDK1023: A PackageReference for 'xunit.core' was included in your project. This package 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 [D:\efcore\test\EFCore.Specification.Tests\EFCore.Specification.Tests.csproj]

However, if I comment out the PackageReferences I get compiler errors saying that it can't find xUnit.net types.

For now, I've worked around the issue by adding <NoWarn>NETSDK1023</NoWarn>, but it would be good to understand why IsImplicitlyDefined="true" is affecting this project when the package reference clearly isn't being added outside of the project.

Release Note Category

  • Feature changes/additions
  • Bug fixes
  • Internal Infrastructure Improvements

Release Note Description

bricelam added a commit to dotnet/efcore that referenced this issue Jun 12, 2023
dotnet-maestro bot added a commit to dotnet/efcore that referenced this issue Jun 12, 2023
[main] Update dependencies from dotnet/arcade


 - Work around dotnet/arcade#13798
@missymessa
Copy link
Member

@agocke can you help here?

@missymessa
Copy link
Member

ping @agocke :)

@agocke
Copy link
Member

agocke commented Oct 5, 2023

Could I get a binlog from the efcore build? I looked through the source and the reason wasn't obvious.

@missymessa
Copy link
Member

@bricelam can you help @agocke help you? :)

@bricelam
Copy link
Contributor Author

Steps:

  1. Clone dotnet/efcore
  2. Search for NETSDK1023 and remove it
  3. Get a binlog

@riarenas riarenas added the area-Infrastructure-libraries Area maintained by .NET libraries team: APICompat, AsmDiff, GenAPI, GenFacades, PkgProj, etc label Nov 30, 2023
@AndriySvyryd
Copy link
Member

Also, when using CPM, adding this to Directory.Packages.props:

    <PackageVersion Include="xunit.assert" Version="$(XUnitVersion)" />
    <PackageVersion Include="xunit.core" Version="$(XUnitVersion)" />
    <PackageVersion Include="xunit.runner.visualstudio" Version="$(XUnitRunnerVisualstudioVersion)" />

causes

error NU1009: The packages xunit.core;xunit.assert;xunit.runner.visualstudio are implicitly referenced. You do not typically need to reference them from your project or in your central package versions management file. For more information, see https://aka.ms/sdkimplicitrefs

@ericstj
Copy link
Member

ericstj commented Sep 13, 2024

Those are implicitly referenced here:

<PackageReference Include="xunit.core" Version="$(XUnitVersion)" IsImplicitlyDefined="true" PrivateAssets="all" Publish="true" />
<PackageReference Include="xunit.analyzers" Version="$(XUnitAnalyzersVersion)" IsImplicitlyDefined="true" PrivateAssets="all" Publish="true" />
<PackageReference Include="xunit.assert" Version="$(XUnitVersion)" IsImplicitlyDefined="true" PrivateAssets="all" Publish="true" Condition="'$(UseDotNetXUnitAssert)' != 'true' or '$(TargetFrameworkIdentifier)' != '.NETCoreApp'" />

Seems like those targets are imported here: https://github.com/dotnet/arcade/blob/bd749a18dd72b8fcb5257ae01a4faf6dd487cc5f/src/Microsoft.DotNet.Arcade.Sdk/tools/Tests.targets#L15-L23C6

I guess you're meant to just set XUnitVersion. It seems this goes back to this change by @AndyGerlicher 6b1db29 which explicitly mentions doing this to work better with CPM.

@AndriySvyryd
Copy link
Member

I guess you're meant to just set XUnitVersion.

The problem is that we still need to reference those packages and set the version to avoid errors https://github.com/dotnet/efcore/blob/release/9.0/test/EFCore.Specification.Tests/EFCore.Specification.Tests.csproj#L62-L64

@agocke
Copy link
Member

agocke commented Sep 14, 2024

As far as I can see, there's nothing strange about the Arcade usage of implicit package references here.

The two possible questions are:

  1. Should Arcade have implicit package references?
  2. Is the implicit package reference behavior in NuGet correct?

Regarding (1), this configuration long predates my involvement, and the "official" support for implicit references seems to indicate this is a supported scenario. I don't see anything necessarily wrong with Arcade's behavior here.

For (2), this is a question for the NuGet team.

I'm closing this as not relevant for the Arcade repo. This can be re-opened as a NuGet issue if (2) is in question.

@agocke agocke closed this as not planned Won't fix, can't repro, duplicate, stale Sep 14, 2024
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Infrastructure-libraries Area maintained by .NET libraries team: APICompat, AsmDiff, GenAPI, GenFacades, PkgProj, etc
Projects
None yet
Development

No branches or pull requests

7 participants
@agocke @bricelam @AndriySvyryd @ericstj @riarenas @missymessa and others