簡體   English   中英

在VS2017中定位多個框架時發布失敗

[英]Publish Fails when targeting multiple frameworks in VS2017

在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>

您一次只能發布一個框架,因此您必須在執行dotnet publish命令時指定要發布的目標框架。

dotnet publish -f = netcoreapp1.1

要么

dotnet publish -f = net462

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM