在VS2017中定位多个框架时发布失败

时间:2017-03-23 16:48:44

标签: visual-studio asp.net-core nuget visual-studio-2017

在Visual Studio 2017项目(netcoreapp1.1; net462)中定位多个框架时

每次尝试发布时,发布都会失败并显示错误:

  

“如果没有指定目标框架,则不支持'发布'目标。当前项目针对多个框架,请指定已发布应用程序的框架”

我已经制定了我的属性组条件,但我还需要做些什么才能“为已发布的应用程序指定框架”。我错过了什么吗?

此外 - 项目编制正常。此外,值得注意的是,它是在VS 2015中创建的项目,并转换为VS 2017项目。

这是.csproj:

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFrameworks>netcoreapp1.1;net462</TargetFrameworks>
    <PreserveCompilationContext>true</PreserveCompilationContext>
    <AssemblyName>Project.WebApp</AssemblyName>
    <OutputType>Exe</OutputType>
    <PackageId>Project.WebApp</PackageId>
    <RuntimeFrameworkVersion Condition=" '$(TargetFramework)' == 'netcoreapp1.1' ">1.1.1</RuntimeFrameworkVersion>
  </PropertyGroup>
  <ItemGroup>
    <None Include="App.config" />
    <None Update="wwwroot\**\*">
      <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
    </None>
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\Data\Proj.Data.csproj" />
    <ProjectReference Include="..\Proj.Data\Proj.Data.csproj" />
    <ProjectReference Include="..\Proj.Web.Client\Proj.Web.Client.csproj" />
    <ProjectReference Include="..\Proj.Web.Models\Proj.Web.Models.csproj" />
    <ProjectReference Include="..\Proj.Services.Client\Proj.Services.Client.csproj" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="AngleSharp" Version="0.9.9" />
    <PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
    <PackageReference Include="Microsoft.AspNetCore.Rewrite" Version="1.0.1" />
    <PackageReference Include="Microsoft.AspNetCore.Routing" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.1" />
    <PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.0" />
  </ItemGroup>
  <ItemGroup Condition=" '$(TargetFramework)' == 'net462' ">
    <Reference Include="System" />
    <Reference Include="Microsoft.CSharp" />
  </ItemGroup>
  <Target Name="PrepublishScript" BeforeTargets="PrepareForPublish" Condition=" '$(IsCrossTargetingBuild)' != 'true' ">
    <Exec Command="bower install" />
    <Exec Command="dotnet bundle" />
  </Target>
  <ItemGroup>
    <DotNetCliToolReference Include="BundlerMinifier.Core" Version="2.2.301" />
  </ItemGroup>
</Project>

此处还有发布配置文件,它似乎指定了发布框架:

<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121. 
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <PublishFramework>netcoreapp1.1</PublishFramework>
    <ProjectGuid>3794908a-5af3-4dba-bb6a-8d846b773ff7</ProjectGuid>
    <publishUrl>\\app\Applications\App\Web Site\</publishUrl>
    <DeleteExistingFiles>True</DeleteExistingFiles>
  </PropertyGroup>
</Project>

编辑:适用于我的解决方案 我尝试使用命令行并指定要发布的版本的@Stan88解决方案。这对我来说不起作用,因为我的PrepublishScript由于某种原因失败了。

最终对我有用的是基本上编辑我的.csproj文件,只针对netcoreapp1.1框架。但是,最后我最终意识到我的PrepublishScript存在问题并最终在.csproj文件中删除对它的引用 - 所以最后我认为Stan88的命令行解决方案如果没有用于预先发布的疯狂,那么,标记为正确

这是我的.csproj最终看起来像。

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFrameworks>netcoreapp1.1</TargetFrameworks>
    <PreserveCompilationContext>true</PreserveCompilationContext>
    <AssemblyName>Project.WebApp</AssemblyName>
    <OutputType>Exe</OutputType>
    <PackageId>Project.WebApp</PackageId>
  </PropertyGroup>
  <ItemGroup>
    <None Include="App.config" />
    <None Update="wwwroot\**\*">
      <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
    </None>
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\Data\Proj.Data.csproj" />
    <ProjectReference Include="..\Proj.Data\Proj.Data.csproj" />
    <ProjectReference Include="..\Proj.Web.Client\Proj.Web.Client.csproj" />
    <ProjectReference Include="..\Proj.Web.Models\Proj.Web.Models.csproj" />
    <ProjectReference Include="..\Proj.Services.Client\Proj.Services.Client.csproj" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="AngleSharp" Version="0.9.9" />
    <PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
    <PackageReference Include="Microsoft.AspNetCore.Rewrite" Version="1.0.1" />
    <PackageReference Include="Microsoft.AspNetCore.Routing" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.1" />
    <PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.0" />
  </ItemGroup>
  <ItemGroup>
    <DotNetCliToolReference Include="BundlerMinifier.Core" Version="2.2.301" />
  </ItemGroup>
</Project>

1 个答案:

答案 0 :(得分:3)

您一次只能发布一个框架,因此您必须在执行dotnet publish命令时指定要发布的目标框架。

dotnet publish -f = netcoreapp1.1

dotnet publish -f = net462