Search code examples
msbuildvisual-studio-2017.net-standard-2.0

Multitargeting .NET Standard 2.0 missing some framework libraries


Had a working ASP.NET Core using a .NET Standard DLL I wrote. I'd like to use TransactionScope in my DLL now, but getting this issue:

.NET Standard and .NET Core 2.0 both recognize System.Transactions, but .NET Framework 4.6.1 is giving an error and won't compile with MSBuild. Visual Studio 2017 offers the following helpful information:

evil tooltip

I cannot seem to find a way to force the project to recognize System.Transactions.dll from my system's Framework/Framework64 folders.

Yes, I can use dotnet build to compile the .NET Core version, but that's not what I want... I want to be able to compile for .NET 4.6.1, too.


Solution

  • You need to add a framework referenced conditioned on the target framework.

    Add this to your csproj file:

    <ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
      <Reference Include="System.Transactions" />
    </ItemGroup>