vstest
vstest copied to clipboard
Build fails after update from 17.6.0 to 17.6.1
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>
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?
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>
Tried that as well, still nothing. What version of dotnet sdk are you using? (dotnet --version
)
❯❯ dotnet --version 7.0.302
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
.
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.
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.