Description
openedon Oct 27, 2022
Description
The Microsoft.NET.Test.Sdk NuGet package version 17.4.0-preview-20220726-02 and later now always inserts buildTransitive/netcoreapp3.1/Microsoft.NET.Test.Sdk.Program.cs
into to the build of referencing projects, which can result in CS0017 build errors.
Steps to reproduce
Download and extract vstest-cs0017.zip.
The project consists of two projects, App
and TestHelper
. App.csproj
has @(ProjectReference)
to TestHelper.csproj
, and TestHelper.csproj
has a @(PackageReference)
to two different versions of Microsoft.NET.Test.Sdk
, depending on whether $(UseStable)
is True.
Build the project:
cd vstest-cs0017
dotnet build App/App.csproj
Expected behavior
It builds!
Actual behavior
It doesn't build:
Program.cs(2,24): error CS0017: Program has more than one entry point defined. Compile with /main to specify the type that contains the entry point.
However, if you use an older Microsoft.NET.Test.Sdk package version, it does build!
dotnet build App/App.csproj -p:UseStable=True
# no errors!
Discussion
The problem is caused solely by the Microsoft.NET.Test.Sdk package version. App.csproj
builds when using 16.11.0, and fails with 17.5.0-preview-20221003-04.
The breakage appears to have been introduced between 17.4.0-preview-20220707-01 (works) and 17.4.0-preview-20220726-02 (fails). The primary difference appears to be that 17.4.0-preview-20220726-02 moved build/netcoreapp2.1/Microsoft.NET.Test.Sdk.Program.cs
to buildTransitive/netcoreapp2.1/Microsoft.NET.Test.Sdk.Program.cs
, causing it to be included into indirectly referencing projects such as App.csproj
.
Workaround
Use an older version of Microsoft.NET.Test.Sdk.
Or set the $(StartupObject)
MSBuild property.
Or do as #636 suggests and set $(GenerateProgramFile)
=false.
Environment
This is with .NET 7.0.100-rc.1.22431.12.