visual-studioxamarinblazorvisual-studio-mac.net-7.0

I can't compile a Visual Studio Solution with Blazor Client/Server/Shared projects and Xamarin App/App.iOS/App.Android projects


I would like to create a Visual Studio slution with 6 projects:

The first I did was create two individual solutions with the Visual Studio Wizard, the first one with the Blazor template and the second one with the Xamarin template.

I close the Xamarin solution and then I try to add the projects of the Xamarin solution one by one. The first one was the XamarinApp and I try to compile and works fine. The second one was the XamarinApp.iOS and when I try to compile fails. It happends the same remove this project and adding the XamarinApp.Android.

First I susspected that the problem is the Debug|iPhoneSimulator and Debug|iPhone, but when it fails also with the XamarinApp.Android project that it not contains the Debug|iPhone and Debug|iPhoneSimulator I was lost.

The error I obtain when I try to compile is (translated the text from spanish to english to do more clear it):

Target ResolvePackageAssets: /Users/myuser/Library/Caches/VisualStudio/17.0/MSBuild/1140_3/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error NETSDK1005: The resource file "/Users/myuser/Projects/MySolution/Blazor.Shared/obj/project.assets.json" does not have a target for ".NETFramework,Version=v7.0". be sure that that the restore was executed and that it included "net70" in TargetFrameworks for your project. Finished compilation of target "ResolvePackageAssets" in project "Blazor.Shared.csproj" -- ERROR.

Build of project "Blazor.Shared.csproj" finished -- ERROR.

If I remove the XamarinApp.Andriod and XamarinApp.iOS from solution, all projects compile again.

Any idea?

EDIT: I discovered that when I add the XamarinApp.Android and XamarinApp.iOS, the "Build with MSBuild on Mono" option pass to be checked. If I uncheck this option all projects but XamarinApp.Android and XamarinApp.iOS compiles, and for this projects the error is the next one:

ERROR al compilar.

CSC : error CS0006: Metadata file '/Users/acayon/Projects/MySolution/XamarinApp/bin/Debug/netstandard2.0/ref/XamarinApp.dll' could not be found 0 Advertencia(s) 1 Errores


Solution

  • According to the error log below:

    CSC : error CS0006: Metadata file '/Users/acayon/Projects/MySolution/XamarinApp/bin/Debug/netstandard2.0/ref/XamarinApp.dll' could not be found 0 Advertencia(s) 1 Errores

    You need to update the .NET Standard's property group with ProduceReferenceAssemblyInOutDir set to true in your csproj file as Matt suggested like below:

    <PropertyGroup>     
        <ProduceReferenceAssemblyInOutDir>true</ProduceReferenceAssemblyInOutDir>   
    </PropertyGroup>
    

    This is because if an external system requires the reference assembly in OutDir, you need to set the MSBuild property ProduceReferenceAssemblyInOutDir to true in your project file.