Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# .NETStandard多目标库包在NETStandard 2.0项目中给了我CS0234错误_C#_Asp.net Core_.net Standard - Fatal编程技术网

C# .NETStandard多目标库包在NETStandard 2.0项目中给了我CS0234错误

C# .NETStandard多目标库包在NETStandard 2.0项目中给了我CS0234错误,c#,asp.net-core,.net-standard,C#,Asp.net Core,.net Standard,因此,我必须将一个项目从.NET Framework重构为NET标准,NET标准版本是2.0,而我的.NET Framework版本是4.7.2。 我在csproj中使用多目标定位,因为我仍然需要.NET Framework中一些在.NET标准中不存在的功能,例如System.Runtime.Remoting。 我原以为多目标可以解决我的Net Standard没有软件包的问题,但它给了我这个错误: 错误CS0234中不存在类型或命名空间名称“Remoting” 命名空间“System.Runt

因此,我必须将一个项目从.NET Framework重构为NET标准,NET标准版本是2.0,而我的.NET Framework版本是4.7.2。 我在csproj中使用多目标定位,因为我仍然需要.NET Framework中一些在.NET标准中不存在的功能,例如System.Runtime.Remoting。 我原以为多目标可以解决我的Net Standard没有软件包的问题,但它给了我这个错误:

错误CS0234中不存在类型或命名空间名称“Remoting” 命名空间“System.Runtime”是否缺少程序集 参考Project.StandardNetstandard2.0

这是我的Csproj:

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFrameworks>netstandard2.0;net472</TargetFrameworks>
        <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
    </PropertyGroup>

    <ItemGroup Condition="'$(TargetFramework)'=='net472'">
        <Reference Include="System.Runtime.Remoting" />
    </ItemGroup>


</Project>

由于某些原因,我的代码无法在需要时以.NET Framework为目标,或者我的Csproj中缺少了什么内容?

您的Csproj文件设置正确。我将假设有一些源代码引用程序集

您需要找出在源代码中引用它的位置,并将其环绕在如下指令中:

public class Class1
{
    public void TestMe()
    {
#if NET472
        var test = new System.Runtime.Remoting.Metadata.SoapAttribute();
#endif
    }
}

这将确保它仅在为.NET Framework 4.7.2而非.NET标准编译时可见。

您的CSPROJ文件设置正确。我将假设有一些源代码引用程序集

您需要找出在源代码中引用它的位置,并将其环绕在如下指令中:

public class Class1
{
    public void TestMe()
    {
#if NET472
        var test = new System.Runtime.Remoting.Metadata.SoapAttribute();
#endif
    }
}

这将确保它仅在为.NET Framework 4.7.2而不是.NET标准编译时可见。

您试图使用标准中根本不存在的功能远程处理。如果其中一个目标只是返回null或抛出NotSupportedException或类似值,那么多目标库没有任何意义。您正在尝试使用标准中根本不存在的功能远程处理。如果其中一个目标只是返回null或抛出NotSupportedException或类似值,那么多目标库就没有意义了。