Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referencing a .netstandard2_0 project in a platform.uno project

To reproduce:

Download https://github.com/nventive/Uno.QuickStart

Add a .NETStandard2_0 project called TestMe.

Reference TestMe in the MyApp.Droid project.

Building MyApp.Droid brings compile error:

System.InvalidOperationException: The project(s) TestMe did not provide any metadata reference. This may be due to an invalid path, such as $(SolutionDir) being used in the csproj; try using relative paths instead.This may also be related to a missing default configuration directive. Refer to the Uno.SourceGenerator Readme.md file for more details. at Uno.SourceGeneration.Host.SourceGeneratorHost.d__4.MoveNext() in C:\projects\uno-sourcegeneration\src\Uno.SourceGenerationHost.Shared\SourceGeneratorHost.cs:line 303 MyApp.Droid

I already tried to change TestMe.csproj to

<TargetFrameworks>net461;netstandard2.0</TargetFrameworks>

or

<TargetFrameworks>net47;netstandard2.0</TargetFrameworks>

without success.

Is there a workaround for this problem?

like image 510
Henk Avatar asked May 30 '18 15:05

Henk


2 Answers

Unfortunately, this is a known Roslyn issue here: https://github.com/nventive/Uno.SourceGeneration/issues/2

To work around this, you must include all the platforms you want to support in your TargetFrameworks node, which in your case is MonoAndroid80 (or similar).

like image 109
Jérôme Laban Avatar answered Oct 10 '22 09:10

Jérôme Laban


Thanks to Jerome i found the xamarin target framework moniker https://docs.microsoft.com/en-us/xamarin/cross-platform/app-fundamentals/nuget-manual

The problem is that the default < Project Sdk="Microsoft.NET.Sdk" > of the .NETStandard project doesn't allow xamarin target frameworks. The solution is to use https://github.com/onovotny/MSBuildSdkExtras

Reading the README.md suggest that from VS15.6+ you can exchange < Project Sdk="Microsoft.NET.Sdk"> with < Project Sdk="MSBuild.Sdk.Extras/1.2.2">

the updated TestMe.csproj must look like this

<Project Sdk="MSBuild.Sdk.Extras/1.2.2">
 <PropertyGroup>
   <TargetFrameworks>netstandard2.0;MonoAndroid81;xamarinios10</TargetFrameworks>
 </PropertyGroup>

ATTENTION: The monodroid moniker of the .netstandard project must match exactly the Android project version. --> MonoAndroid81 for Oreo8.1

UPDATE: Instead of writing

<Project Sdk="MSBuild.Sdk.Extras/1.2.2">

one can also write

<Project Sdk="Microsoft.NET.Sdk">
  <Import Project="$(MSBuildSDKExtrasTargets)" Condition="Exists('$(MSBuildSDKExtrasTargets)')" />
like image 39
Henk Avatar answered Oct 10 '22 09:10

Henk