如果不指定目标框架,则不支持"发布"目标

Ada*_*dam 9 msbuild publish asp.net-core .net-4.6.2 visual-studio-2017

使用Visual Studio 2017,我使用.NET Framework创建了一个ASP.NET Core站点.(我没有project.json,我有一个VS2017项目.cproj)

我的目标是x64 Windows 2008R2.我.cproj看起来像下面的开头:

<Project Sdk="Microsoft.NET.Sdk.Web" ToolsVersion="15.0">
  <PropertyGroup>
    <TargetFrameworks>net462</TargetFrameworks>
    <RuntimeIdentifier>win7-x64</RuntimeIdentifier>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <PlatformTarget>x64</PlatformTarget>
    <OutputPath>bin\Debug</OutputPath>
    <DefineConstants>TRACE;DEBUG</DefineConstants>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <PlatformTarget>x64</PlatformTarget>
    <OutputPath>bin\Release</OutputPath>
    <Optimize>True</Optimize>
  </PropertyGroup>
  ...
Run Code Online (Sandbox Code Playgroud)

但是,虽然我只针对.NET 4.6.2,但当我尝试发布时,我收到此错误

C:\ Program Files(x86)\ Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk\buildCrossTargeting\Microsoft.NET.Sdk.targets(31,5):错误:'发布'目标是不指定目标框架就不受支持.当前项目针对多个框架,请指定已发布应用程序的框架.

在网上寻找解决方案的同时,我遇到了遇到同样问题的人,但他们确实有很多目标,但是,在我的情况下,我不确定为什么我会得到它.

有任何想法吗?

Set*_*Set 22

.csproj模板发生了变化(https://github.com/dotnet/sdk/issues/251).而不是<TargetFrameworks>你需要使用<TargetFramework>:

<PropertyGroup>
   <TargetFramework>net462</TargetFramework>
   <RuntimeIdentifier>win7-x64</RuntimeIdentifier>
 </PropertyGroup>
Run Code Online (Sandbox Code Playgroud)

  • 为什么它不能查看列表,看到只列出了一个框架,然后按照“TargetFramework”执行操作? (5认同)
  • 此信息现在可能已过期.我相信`TargetFrameworks`(复数)已经卷土重来.请参阅:/sf/ask/2992358421/ (3认同)
  • @tjrobinson,如果您需要支持一个以上的框架,则应使用TargetFrameworks;否则,请使用TargetFramework,否则您将看到您的项目针对多个框架。运行应用程序时出错(例如dotnet run)。 (2认同)