vstest icon indicating copy to clipboard operation
vstest copied to clipboard

Build fails after update from 17.6.0 to 17.6.1

Open Lyra2108 opened this issue 1 year ago • 7 comments

Description

When I update the tests projects in my solution to 17.6.1 they all fail to build with the message

Programa não contém um método "Main" estático adequado para um ponto de entrada

(English translation: Missing static Main method)

17.6.0 builds fine.

Environment

The test solutions look mostly like this

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
    <OutputType>Library</OutputType>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <LangVersion>11.0</LangVersion>
  </PropertyGroup>
  <ItemGroup>
    <RuntimeHostConfigurationOption Include="System.Globalization.UseNls" Value="true" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\baseprojecttotest.csproj" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.1" />
    <PackageReference Include="Moq" Version="4.18.4" />
    <PackageReference Include="NUnit" Version="3.13.3" />
    <PackageReference Include="NUnit.Analyzers" Version="3.6.1">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
  </ItemGroup>
</Project>

Lyra2108 avatar Jun 02 '23 13:06 Lyra2108

I created a new project with your code and only removed <ProjectReference Include="..\baseprojecttotest.csproj" /> from it. It does not repro for me. Could you please try the same on your system?

nohwnd avatar Jun 02 '23 13:06 nohwnd

This is the reference to the project which I want to test it was just an example here. So that is needed (and existing on my side)

The csproj you removed usually looks like this TargetFrameworks are netstandard like in the example or net6.0

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
    <OutputType>Library</OutputType>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <LangVersion>11.0</LangVersion>
  </PropertyGroup>
  <ItemGroup>
    <RuntimeHostConfigurationOption Include="System.Globalization.UseNls" Value="true" />
  </ItemGroup>
</Project>

Lyra2108 avatar Jun 02 '23 13:06 Lyra2108

Tried that as well, still nothing. What version of dotnet sdk are you using? (dotnet --version)

nohwnd avatar Jun 02 '23 13:06 nohwnd

❯❯ dotnet --version 7.0.302

Lyra2108 avatar Jun 02 '23 14:06 Lyra2108

I am using the same by forcing it via global.json, and it still works for me just fine. Are you able to reproduce this across mutiple computers? Are you also able to repro when you dotnet clean, or when you run (WARNING this is destructive, so make sure you have no changes you want to keep) git clean -fdx.

nohwnd avatar Jun 02 '23 14:06 nohwnd

That does not change anything still it builds with 17.6.0 and does not with 17.6.1 I cleaned after each version change

CSC : error CS5001: Programa não contém um método "Main" estático adequado para um ponto de entrada

It looks like that for some reason the libraries are treated as a console application.

Lyra2108 avatar Jun 02 '23 14:06 Lyra2108

Yes, .NET test projects are creating a main method and setting output type to exe to generate runtimeconfig.json so the testhost can know what TFM you are targetting and run your tests.

But I am using the same project configuration as you do, and it works even with 17.6.1.

nohwnd avatar Jun 02 '23 14:06 nohwnd