Visual Studio 2017 RCでvNext形式の.NET xUnitテストプロジェクト(project.json)を新しい.csproj形式に変換し、以下のエラーが発生しました。このエラーのオンライン回答のほとんどは、 "あなたは2つの主要な方法を持っています。これは明らかな解決策のようですが、このプロジェクトにはメインメソッドが1つしかありません。XUnitテストプロジェクトは1つしかありませんメインメソッド: "プログラムに複数のエントリポイントが定義されています。"
エラー:
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);
}
}
}
旧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": {}
}
}
新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>
ありがとう。私はVS2017で開いたばかりのMSTestを使ったプロジェクトを持っていて、同じ問題を表示したcsprojに移行しました。 – Nick
ありがとう!私は内部のもののために私のWebアプリケーションに焼き込まれたxunitテストを持っており、これまで合理的な説明がなくこれを得ました。 – Yablargo