Reputation: 71
So I have to refactor a project from .NET Framework
to Net Standard
, the Net Standard
version is 2.0
and my .NET Framework
version is 4.7.2
.
I am using multi targeting in my csproj because I still need some functionalities from .NET Framework
that don't exist in .NET Standard
, for example, System.Runtime.Remoting
.
I thought that multi targeting would solve my problem of Net Standard
not having the package, but it is giving me this error:
Error CS0234 The type or namespace name 'Remoting' does not exist in the namespace 'System.Runtime' (are you missing an assembly reference?) Project.Standard (netstandard2.0)
This is my 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>
For some reason my code isn't able to target the .NET Framework
when it needs to or am I missing something in my Csproj?
Upvotes: 1
Views: 463
Reputation: 13547
Your CSPROJ file is setup properly. I am going to assume there is some source code that is referencing the assembly.
You need to figure out where in your source code you are referencing it and surround it in a directive that looks like this:
public class Class1
{
public void TestMe()
{
#if NET472
var test = new System.Runtime.Remoting.Metadata.SoapAttribute();
#endif
}
}
This will ensure it only is visible when it's compiled for .NET Framework 4.7.2 and not .NET Standard.
Upvotes: 3