Azure Cloud Service Classic with .NET Standard target

纵然是瞬间 提交于 2020-03-21 19:26:33

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/47160949/azure-cloud-service-classic-with-net-standard-target

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!