Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The 'Publish' target is not supported without specifying a target framework

Using Visual Studio 2017, I created an ASP.NET Core site using .NET Framework. (I do not have a project.json, I have a VS2017 project with .cproj)

My target is x64 Windows 2008R2. The beginning of my .cproj looks like follow:

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

However, and while I am targetting .NET 4.6.2 only, when I try to publish I am getting this error

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk\buildCrossTargeting\Microsoft.NET.Sdk.targets(31,5): 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.

While looking for solutions online, I encountered people having the same problem but they actually have many targets, however, in my case I am not sure why I am even getting it.

Any ideas?

like image 280
Adam Avatar asked Apr 10 '17 10:04

Adam


People also ask

How do I change my target framework to .NET 6?

To set target . NET runtime version to 6.0, enter <TargetFramework>net6. 0</TargetFramework> version in project's . csproj file directly.

What is target framework in web config?

The reason of targetFramework existence in web. config is to keep compatibility issues out between breaking changes for each version of . NET Framework. The difference between targetFramework on compilation and httpRuntime belongs to each development and deployment environment.


1 Answers

There was a change in the .csproj template (https://github.com/dotnet/sdk/issues/251). Instead of <TargetFrameworks> you need to use <TargetFramework>:

<PropertyGroup>
   <TargetFramework>net462</TargetFramework>
   <RuntimeIdentifier>win7-x64</RuntimeIdentifier>
 </PropertyGroup>
like image 156
Set Avatar answered Oct 20 '22 20:10

Set