8

Is there a way how to run Azure Cloud Service Classic project with worker role that targets .netstandard2.0?

I have such project, but any time I try to build it I receive this error:

Severity Code Description Project File Line Suppression State Error Project 'C:\path\to\project\src\Frontend\Frontend.csproj' targets '.NETStandard,Version=v2.0'. It cannot be referenced by a project that targets '.NETFramework,Version=v4.0'. UserDiscoveryService C:\Program Files\dotnet\sdk\2.0.2\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.Common.targets 87

I tried to set target framework inside ccproj, but it didn't helped me.

Martin Obrátil
  • 165
  • 1
  • 7
  • Have you tried following the steps located here: https://github.com/dotnet/sdk/issues/1241 Also is this build runing on your local machine or on VSTS – ObiEff Nov 07 '17 at 15:01
  • Thank you @ObiEff, but this seems unrelated to my problem. I have problem with referencing .netstandard project from cloud service project. Thread on github is about referencing from netcoreapp2.0. – Martin Obrátil Nov 07 '17 at 15:10

2 Answers2

8

Just in case anyone else encounters this, I got past this error by adding this line to the Project/PropertyGroup section of the cloud service .ccproj file: <TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>

e.g.

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>2.9</ProductVersion>
    <ProjectGuid>8c99xxxx-xxxx-xxxx-xxxx-xxxxxxxx273e</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>MyCloudService</RootNamespace>
    <AssemblyName>MyCloudService</AssemblyName>
    <TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion> <!-- Added -->
    <StartDevelopmentStorage>True</StartDevelopmentStorage>
    <Name>CloudSheetCloudService</Name>
    etc...

By default the cloud services project does not specify the framework (it doesn't need to) but something in MSBuild appears to be doing a version check between the cloud service and the web / worker roles and then failing the build.

Changing the tools version did not help.

As background - I have an old cloud service that references a 4.6.2 project that uses the new csproj style like this:

<Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
     <TargetFramework>net462</TargetFramework>
   </PropertyGroup>
</Project>

HTH. Mark.

Edit: The file to edit is the .ccproj not the .cproj file as previously stated.

Kit
  • 2,418
  • 11
  • 21
MarkD
  • 1,131
  • 12
  • 27
  • 2
    Really useful info thanks. I think it's the .ccproj not the .csproj which needs the extra line - I've put in an edit which is awaiting review. – Kit Dec 06 '18 at 16:24
0

Severity Code Description Project File Line Suppression State Error Project 'C:\path\to\project\src\Frontend\Frontend.csproj' targets '.NETStandard,Version=v2.0'. It cannot be referenced by a project that targets '.NETFramework,Version=v4.0'.

Based on the error, your Frontend.csproj project targets .NETStandard 2.0 and you referenced the .NETStandard 2.0 project from a project targets .NETFramework V4.0. As the official documentation about .NET Standard, you need to at least make your project targets .NETFramework V4.6.1 for referencing the .NETStandard 2.0 project or library. Or you need to choose the lower .NET Standard version, more details you need to follow .NET implementation support.

Bruce Chen
  • 17,123
  • 2
  • 14
  • 27