Bug 53060 - Fail to compile .NET Standard Class Library in VS2017
Summary: Fail to compile .NET Standard Class Library in VS2017
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.4
Hardware: PC Windows
: Normal major
Target Milestone: ---
Assignee: Chris King
URL:
Depends on:
Blocks:
 
Reported: 2017-03-05 02:52 UTC by Adam
Modified: 2017-07-22 13:13 UTC (History)
14 users (show)

Tags: xamlc netstandard ac
Is this bug a regression?: ---
Last known good build:


Attachments
Reproduction (1.39 KB, application/x-zip-compressed)
2017-03-05 02:52 UTC, Adam
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Adam 2017-03-05 02:52:19 UTC
Created attachment 20134 [details]
Reproduction

If I create a .NET Standard Class Library in Visual Studio 2017 and reference Xamarin Forms (any version), it will fail to compile.

If you go to Diagnostic on the Build output you receive this error

1>Done building target "AfterCompile" in project "ClassLibrary1.csproj".
1>Target "XamlC" in file "C:\Users\Adam\.nuget\packages\xamarin.forms\2.3.4.192-pre2\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets":
1>  Using "XamlCTask" task from assembly "C:\Users\Adam\.nuget\packages\xamarin.forms\2.3.4.192-pre2\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.Build.Tasks.dll".
1>  Task "XamlCTask"
1>    Task Parameter:Assembly=obj\x86\Debug\netstandard1.3\ClassLibrary1.dll
1>    Task Parameter:ReferencePath=C:\Users\Adam\.nuget\packages\microsoft.win3 ... etc (shortened to make it easier to read)
1>    Task Parameter:Verbosity=2
1>    Task Parameter:OptimizeIL=True
1>    Task Parameter:DebugSymbols=True
1>    Compiling Xaml
1>    
1>    Assembly: obj\x86\Debug\netstandard1.3\ClassLibrary1.dll
1>    ReferencePath: 	C:\Users\Adam\.nuget\packages\microsoft.win32.primitives\4.0.1\ref\netstandard1.3\Mic ... etc (shortened to make it easier to read)
1>  Done executing task "XamlCTask" -- FAILED.
1>
1>  Done building project "ClassLibrary1.csproj" -- FAILED.

The csproj is just this.

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

  <PropertyGroup>
    <TargetFramework>netstandard1.3</TargetFramework>
    <PackageTargetFallback>$(PackageTargetFallback);portable-win+net45+wp8+win81+wpa8</PackageTargetFallback>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Xamarin.Forms" Version="2.3.4.192-pre2" />
  </ItemGroup>

</Project>

Attached is an example.

If I go to the Xamarin.Forms.targets in the nuget package and remove the XamlC from this section

	<PropertyGroup>
		<CompileDependsOn>
			$(CompileDependsOn);
			XamlC;
		</CompileDependsOn>
	</PropertyGroup>

It will build and run correctly, but now without XamlC support.
Comment 1 Paul DiPietro [MSFT] 2017-03-06 16:04:17 UTC
This will need more investigation, but it looks to be doing the same thing on my machine so I'll mark it as confirmed for now.
Comment 2 Viktor Hofer 2017-03-08 16:10:58 UTC
Same for me. Currently road blocker for migrating Xamarin Forms PCL to netstandard.
Comment 3 Stavros Kasidis 2017-03-09 08:10:20 UTC
I can also confirm the issue. This prevents me from migrating to .Net Standard, which is required for me because I have a shared codebase with .Net core and Xamarin forms.
Comment 4 NorDroN 2017-03-09 14:51:20 UTC
I have the same problem
I think it can be associated with https://github.com/dotnet/cli/issues/5457 

error MSB4062: The "Xamarin.Forms.Build.Tasks.FixedCreateCSharpManifestResourceName" task could not be loaded from the assembly /home/xxxx/.nuget/packages/xamarin.forms/2.3.3.180/build/portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20/Xamarin.Forms.Build.Tasks.dll. Could not load file or assembly 'Microsoft.Build.Utilities.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. 
error MSB4062:  Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.
Comment 5 NorDroN 2017-03-09 15:07:16 UTC
And I think you should port Xamarin.Forms.Build.Tasks on Microsoft.NET.Sdk for .NET Core ( like this - https://github.com/madskristensen/BundlerMinifier/issues/230 )
Comment 6 Chris King 2017-03-13 20:39:15 UTC
Building from the command line generates an OOM exception with the included stack trace (build.log attached). Here's a link to GitHub source for the top of the frame: (https://github.com/jbevain/cecil/blob/master/symbols/pdb/Microsoft.Cci.Pdb/MsfDirectory.cs). Here's a similar issue (https://github.com/dotnet/roslyn/issues/3915) where CCI throws OOM when emitting EnC info but that doesn't appear to be our issue as there is no obvious emit in the .ctor. 

MSBUILD : error MSB1025: An internal failure occurred while running MSBuild.
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.

Server stack trace:
   at Microsoft.Cci.Pdb.MsfDirectory..ctor(PdbReader reader, PdbFileHeader head, BitAccess bits)
   at Microsoft.Cci.Pdb.PdbFile.LoadFunctions(Stream read, Dictionary`2& tokenToSourceMapping, String& sourceServerData, Int32& age, Guid& guid)
   at Mono.Cecil.Pdb.PdbReader.PopulateFunctions()
   at Mono.Cecil.Pdb.PdbReader.ProcessDebugHeader(ImageDebugDirectory directory, Byte[] header)
   at Mono.Cecil.ModuleDefinition.ProcessDebugHeader()
   at Mono.Cecil.ModuleDefinition.ReadSymbols(ISymbolReader reader)
   at Mono.Cecil.ModuleReader.ReadSymbols(ModuleDefinition module, ReaderParameters parameters)
   at Mono.Cecil.ModuleReader.CreateModuleFrom(Image image, ReaderParameters parameters)
   at Mono.Cecil.ModuleDefinition.ReadModule(Stream stream, ReaderParameters parameters)
   at Mono.Cecil.ModuleDefinition.ReadModule(String fileName, ReaderParameters parameters)
   at Xamarin.Forms.Build.Tasks.XamlCTask.Compile(IList`1 thrownExceptions)
   at Xamarin.Forms.Build.Tasks.XamlCTask.Execute()
   at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
   at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)
Comment 9 Chris King 2017-03-13 20:54:40 UTC
Verified fixed in beta-2.3.4-pre4.
Comment 10 Viktor Hofer 2017-03-14 09:17:46 UTC
Yes fixed in beta-2.3.4-pre4 inside Visual Studio!

Tried to do a dotnet pack on a netstandard1.0 with Xamarin.Forms (2beta-2.3.4-pre4) which results in this error message:

 Prism -> C:\Users\vikto\Documents\src\Prism\src\Prism\bin\Release\netstandard1.0\Prism.dll
C:\Users\vikto\.nuget\packages\xamarin.forms\2.3.4.212-pre4\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamar
in.Forms.targets(40,3): error MSB4062: The "Xamarin.Forms.Build.Tasks.FixedCreateCSharpManifestResourceName" task could not be loaded from the assem
bly C:\Users\vikto\.nuget\packages\xamarin.forms\2.3.4.212-pre4\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\X
amarin.Forms.Build.Tasks.dll. Could not load file or assembly 'Microsoft.Build.Utilities.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f
5f7f11d50a3a'. The system cannot find the file specified. Confirm that the <UsingTask> declaration is correct, that the assembly and all its depende
ncies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. [C:\Users\vikto\Documents\src\Prism\
src\Xamarin\Prism.Forms\Prism.Forms.csproj]
Comment 11 Viktor Hofer 2017-03-15 09:40:01 UTC
That issue is related to the fact that dotnet build cannot build the netstandard library but msbuild can! So the lightweight open sourced msbuild is beeing used but not able to.
Comment 12 Viktor Hofer 2017-03-15 10:38:29 UTC
I guess there is some tuning required from your side: https://github.com/dotnet/cli/issues/5457#issuecomment-286700959
Comment 13 NorDroN 2017-03-30 10:58:20 UTC
Hi!

I've tried to use 2.3.4.221-pre6, it still doesn't work

C:\Users\aklimov\.nuget\packages\xamarin.forms\2.3.4.221-pre6\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets(40,3): error MSB4062: The "Xamarin.Forms.Build.Tasks.FixedCreateCSharpManifestResourceName" task could not be loaded from the assembly C:\Users\aklimov\.nuget\packages\xamarin.forms\2.3.4.221-pre6\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.Build.Tasks.dll. Could not load file or assembly 'Microsoft.Build.Utilities.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. [e:\Work\XamarinPrismUnityApp1\XamarinPrismUnityApp1\XamarinPrismUnityApp1\XamarinPrismUnityApp1.csproj]
Build FAILED.
Comment 14 Viktor Hofer 2017-04-06 10:29:37 UTC
Issue is resolved with new stable version of Xamarin.Forms :)
Comment 15 Viktor Hofer 2017-04-06 11:38:45 UTC
UPDATE: No it's still not working!! See here: https://github.com/dotnet/cli/issues/5457
Comment 16 LH 2017-05-19 08:25:42 UTC
Sorry guys, but this issue is not resolved, tried all versions of XF starting from 2.3.4.231 include the pre-releases and the dotnet build command still throws an error that it couldn't load the Microsoft.Build.Utilities.v4.0 assembly
Comment 17 Thomas Hagström 2017-07-22 13:13:40 UTC
Can confirm this is not resolved with stable Xamarin.Forms 2.3.4.247

CsProj:

https://github.com/HLinteractive/HLI.Forms.Core/blob/master/HLI.Forms.Core/HLI.Forms.Core.csproj

VSTS Build log (NetCore):

2017-07-22T12:56:36.3143472Z ##[section]Starting: Build
2017-07-22T12:56:36.3143472Z ==============================================================================
2017-07-22T12:56:36.3143472Z Task         : .NET Core
2017-07-22T12:56:36.3153471Z Description  : Build, test and publish using dotnet core command-line.
2017-07-22T12:56:36.3153471Z Version      : 1.0.2
2017-07-22T12:56:36.3153471Z Author       : Microsoft Corporation
2017-07-22T12:56:36.3153471Z Help         : [More Information](https://go.microsoft.com/fwlink/?linkid=832194)
2017-07-22T12:56:36.3153471Z ==============================================================================
2017-07-22T12:56:36.7033503Z [command]"C:\Program Files\dotnet\dotnet.exe" build d:\a\1\s\HLI.Forms.Core\HLI.Forms.Core.csproj --configuration release
2017-07-22T12:56:37.4058663Z Microsoft (R) Build Engine version 15.1.1012.6693
2017-07-22T12:56:37.4058663Z Copyright (C) Microsoft Corporation. All rights reserved.
2017-07-22T12:56:37.4058663Z 
2017-07-22T12:56:38.4524182Z C:\Users\buildguest\.nuget\packages\xamarin.forms\2.3.4.247\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets(40,3): error MSB4062: The "Xamarin.Forms.Build.Tasks.FixedCreateCSharpManifestResourceName" task could not be loaded from the assembly C:\Users\buildguest\.nuget\packages\xamarin.forms\2.3.4.247\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.Build.Tasks.dll. Could not load file or assembly 'Microsoft.Build.Utilities.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. [d:\a\1\s\HLI.Forms.Core\HLI.Forms.Core.csproj]
2017-07-22T12:56:38.5918626Z 
2017-07-22T12:56:38.5928631Z Build FAILED.
2017-07-22T12:56:38.5928631Z 
2017-07-22T12:56:38.5928631Z C:\Users\buildguest\.nuget\packages\xamarin.forms\2.3.4.247\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets(40,3): error MSB4062: The "Xamarin.Forms.Build.Tasks.FixedCreateCSharpManifestResourceName" task could not be loaded from the assembly C:\Users\buildguest\.nuget\packages\xamarin.forms\2.3.4.247\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.Build.Tasks.dll. Could not load file or assembly 'Microsoft.Build.Utilities.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. [d:\a\1\s\HLI.Forms.Core\HLI.Forms.Core.csproj]
2017-07-22T12:56:38.5928631Z     0 Warning(s)
2017-07-22T12:56:38.5928631Z     1 Error(s)
2017-07-22T12:56:38.5928631Z 
2017-07-22T12:56:38.5928631Z Time Elapsed 00:00:01.13
2017-07-22T12:56:38.6188634Z ##[error]Error: C:\Program Files\dotnet\dotnet.exe failed with return code: 1
2017-07-22T12:56:38.6198628Z ##[error]Dotnet command failed with non-zero exit code on the following projects : d:\a\1\s\HLI.Forms.Core\HLI.Forms.Core.csproj
2017-07-22T12:56:38.6228630Z ##[section]Finishing: Build