Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Publish Fails when targeting multiple frameworks in VS2017

When targeting multiple frameworks in Visual Studio 2017 project (netcoreapp1.1;net462)

Every time I try to publish the publish fails with the error:

"The 'Publish' target is not supported without specifying a target framework. The current project targets multiple frameworks, please specify the framework for the published application"

I've got my property group conditionals in place, but what else do I need to do to 'specify the framework for the published application'. Am I missing something?

Further - Project compiles fine. Also, worthy of note it was a project created in VS 2015 and converted to a VS 2017 project.

Here is .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>

Also here is the Publish Profile, it appears to specify a Publish Framework:

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

EDIT: The solution that worked for me I tried @Stan88 solution of just using the command line and specifying the version to publish. This didn't work for me as my PrepublishScript failed for some reason.

In the end what worked for me was basically editing my .csproj file to only target the netcoreapp1.1 framework. However, in the end I ended up realizing my PrepublishScript had issues and ended up deleting reference to it in the .csproj file - so in the end I think Stan88's command line solution would have worked if not for prepublish craziness, hence, marked as correct.

Here is what my .csproj ended up looking like.

<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>
like image 873
Craig Shutko Avatar asked Mar 23 '17 16:03

Craig Shutko


People also ask

Can you have multiple target frameworks?

For SDK-style projects, you can configure support for multiple targets frameworks (TFM) in your project file, then use dotnet pack or msbuild /t:pack to create the package. nuget.exe CLI does not support packing SDK-style projects, so you should only use dotnet pack or msbuild /t:pack .


1 Answers

You can only publish for one framework at a time so you have to specify the target framework to publish for when executing dotnet publish command.

dotnet publish -f=netcoreapp1.1

or

dotnet publish -f=net462

like image 185
Stan88 Avatar answered Nov 15 '22 06:11

Stan88