20

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?

Tseng
  • 61,549
  • 15
  • 193
  • 205
Adam
  • 3,872
  • 6
  • 36
  • 66

1 Answers1

43

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>
Set
  • 47,577
  • 22
  • 132
  • 150
  • 1
    Wow. Never would have found that without your post. – Steve In CO Jul 20 '17 at 01:12
  • 5
    This information may now be out of date. I believe that `TargetFrameworks` (plural) has made a comeback. See: https://stackoverflow.com/questions/42747977/how-do-you-multi-target-a-net-core-class-library-with-csproj – Tom Robinson Oct 12 '17 at 15:01
  • 5
    @tjrobinson you should use `TargetFrameworks` if you need to support more then one framework, otherwise use `TargetFramework` or you will see `Your project targets multiple frameworks.` error when running app (like `dotnet run`) – Set Oct 12 '17 at 15:05
  • 5
    Why can't it look at the list, see that you have only one framework listed and then behave as per the `TargetFramework`? – Andrei Bazanov Mar 28 '21 at 00:12