I converted a vNext format .NET xUnit test project (with project.json) to the new .csproj format in Visual Studio 2017 RC and started getting the below error. Most of the online answers to this error say "You have two Main methods; get rid of one." This seems like an obvious solution, but this project has only one Main method.
Error:
CS0017 Program has more than one entry point defined. Compile with /main to specify the type that contains the entry point. Project.Name C:\path\to\Program.cs
Program.cs:
using XunitProgram = Xunit.Runner.DotNet.Program;
namespace My.Namespace.Tests
{
public static class Program
{
public static void Main(string[] args)
{
XunitProgram.Main(args);
}
}
}
Old project.json:
{
"version": "1.0.0-*",
"testRunner": "xunit",
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true,
"debugType": "full"
},
"dependencies": {
"dotnet-test-xunit": "2.2.0",
"xunit": "2.2.0",
"Microsoft.DotNet.InternalAbstractions": "1.0.0"
},
"frameworks": {
"net462": {}
}
}
New Project.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net462</TargetFramework>
<RuntimeIdentifier>win7-x86</RuntimeIdentifier>
<DebugType>full</DebugType>
<PreserveCompilationContext>true</PreserveCompilationContext>
<AssemblyName>My.Project.Tests</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>My.Project.Tests</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<RootNamespace>My.Project.Tests</RootNamespace>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-preview-20170106-08" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
<PackageReference Include="xunit" Version="2.2.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net462' ">
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<Folder Include="SampleInput\" />
</ItemGroup>
</Project>