Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't run Desktop-Compiled MsBuild tasks installed from NuGet #7600

Closed
djanosik opened this issue Jan 25, 2017 · 16 comments
Closed

Can't run Desktop-Compiled MsBuild tasks installed from NuGet #7600

djanosik opened this issue Jan 25, 2017 · 16 comments

Comments

@djanosik
Copy link

Steps to reproduce

  • Create empty Web / Library project.
  • Add .less file with any valid content.
  • Install Web Compiler extension.
  • Enable compilation of the .less file.
  • Enable compilation on build.
  • Run dotnet restore.
  • Run dotnet build.

See MsBuildTask.zip.

Expected behavior

  • The WebCompiler.CompilerBuildTask task should compile the .less file.

Actual behavior

An exception is thrown:

error MSB4062: The "WebCompiler.CompilerBuildTask" task could not be loaded from the assembly C:\Users\dusan\.nuget\packages\buildwebcompiler\1.11.326\build\..\tools\WebCompiler.exe. 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. [H:\~Temp\MsBuildTask\MsBuildTask\MsBuildTask.csproj]

It is not related to this particular MsBuild task. AFAIK every task installed from nuget won't work from command line. Everything works when running build with VS 2017 RC (15.0.26020.0 D15REL) or msbuild command.

Environment data

.NET Command Line Tools (1.0.0-preview4-004233)

Product Information:
 Version:            1.0.0-preview4-004233
 Commit SHA-1 hash:  8cec61c6f7

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.15014
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\1.0.0-preview4-004233
@livarcocc
Copy link
Contributor

@madskristensen Is this supposed to work on the CLI with core?

@djanosik
Copy link
Author

djanosik commented Jan 25, 2017

@livarcocc It's not about Web Compiler itself. It's more about MsBuild tasks in general. From what I see, there are two versions of MsBuild with exactly the same version number. Both run on the same machine. One of them can build my project, and the other one can't.

I hope this is not caused by some lightweight feature-less MsBuild being used by .NET CLI. It would make the migration from project.json to .csproj meaningless.

@dasMulli
Copy link
Contributor

The underlying issue seems to be that there are currently full framework (+ mono specific) and .net core builds of msbuild.
When targets try to load a task assembly, this may blow up because of incompatibilities. The .net sdk ships with task assemblies for net46 and netcoreapp1.0 and the target files selects the correct assembly for <UsingTask …/> by looking at MSBuildRuntimeType here.
(Apart from that, build packages may also need a recompile against new msbuild assemblies).

@dasMulli
Copy link
Contributor

Lost track of the issues but iirc the idea was that with netstandard2.0, you can use more existing packages and build task assemblies that will work on both full framework and core.

@TheRealPiotrP
Copy link
Contributor

Thanks @dasMulli. Agreed. The packaging of that particular task nupkg causes .NET Core msbuild to attempt to load desktop-compiled task implementations which is not supported for 1.0. Until the 2.0 story becomes more clear, task packages targeting CLI should be authored akin to the SDK package linked above by @dasMulli.

@TheRealPiotrP TheRealPiotrP changed the title Can't run MsBuild tasks installed from NuGet Can't run Desktop-Compiled MsBuild tasks installed from NuGet Feb 1, 2017
@idkiller
Copy link

idkiller commented Feb 3, 2017

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.

I have similar error when I build xamarin.forms project with dotnet cli 1.0.1 (build : cee57bf6c981237d80aa1631cfe83cb9ba329f12)

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

  <PropertyGroup>
    <TargetFramework>netstandard1.6</TargetFramework>
    <PreserveCompilationContext>true</PreserveCompilationContext>
    <PackageTargetFallback Condition=" '$(TargetFramework)' == 'netstandard1.6' ">$(PackageTargetFallback);portable-net45+wpa81+wp8+win8</PackageTargetFallback>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="**\*.cs" />
    <EmbeddedResource Include="**\*.xaml" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="NETStandard.Library" Version="1.6" />
    <PackageReference Include="Microsoft.NETCore.Portable.Compatibility" Version="1.0.1" />
    <PackageReference Include="Xamarin.Forms" Version="2.3.3.180">
      <!-- <ExcludeAssets>Build</ExcludeAssets> -->
    </PackageReference>
  </ItemGroup>

</Project>

This is my csproj file.

I have seen it should be solved in netstandard 2.0.
It is not SDK and CLI issue? I have tried build with netstandard 2.0 on myget but it does not work. (same error)

Anyone know workaround solution without rebuild the target package about this?

@ViktorHofer
Copy link
Member

I also hit that issue with Xamarin.Forms beta package. If i use the full blown msbuild instead of the dotnet build lightweight msbuild version it all works fine.

@dasMulli
Copy link
Contributor

Looks like it is using a PCL tasks assembly. My best guess is that PCL compatibility facade assemblies would need to be deployed with the CLI's msbuild for that to work - which is nontrivial dotnet/msbuild#1542.
@idkiller did you just add some 2.0.0-* packages from myget or did you install and use a CI build of the CLI? if something could make it work, it's a 2.0.0-* CI build of the CLI. If that doesn't work either i'd wait/ask for version of Xamarin.Forms that ships netstandard/netcoreapp build task assemblies.

@ViktorHofer
Copy link
Member

ViktorHofer commented Apr 6, 2017

Issue is resolved with newest Xamarin.Forms version! 👍

UPDATE: no it's not. See below.

@kvbhat
Copy link

kvbhat commented Apr 6, 2017

Hi ViktorHofer,

Thanks for looking into this issue.
I'm facing a similar issue https://github.com/dotnet/cli/issues/6104 and tried it out with latest Xamarin forms (2.3.4.224) but it seems to reproduce the issue.
Is the Xamarin.Forms version you mentioned yet to be released?

Thanks again for looking into this issue.

@ViktorHofer
Copy link
Member

ViktorHofer commented Apr 6, 2017

Yes 2.3.4.224 - just noticed that pack is still not working from the cli. But with Visual Studio 2017 (newest update!) it is working for me now. Also Unit-testing is now working inside VS but not with dotnet test command in cli...

@WildBamboo
Copy link

WildBamboo commented Apr 24, 2017

We're also experiencing this issue. We have a .NET Core app but it runs on the full 4.6.2 framework. We're using Web Compiler for our LESS compilation, and also experience the

error MSB4062: The "WebCompiler.CompilerBuildTask" task could not be loaded from the assembly C:\Users\dusan\.nuget\packages\buildwebcompiler\1.11.326\build\..\tools\WebCompiler.exe. 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 on our build server, which runs dotnet build

Should this be working for us, or do we need to revert back to NodeJS until netstandard 2.0?

@ViktorHofer
Copy link
Member

We have a .NET Core app but it runs on the full 4.6.2 framework

Are you having an ASP.NET Core Application? A netcoreapp doesn't run on full .NET Framework. It either runs as a self contained application (framework bundled with it) or framework dependent (it uses the installed dotnet framework under "C:\Program Files\dotnet".

@WildBamboo
Copy link

Sorry, I get really confused with all these names and how the bits fit together. The project is an ASP.NET Core application, targeting .NET 4.6.2. <TargetFramework>net462</TargetFramework>

@ViktorHofer
Copy link
Member

Could you use msbuild (the desktop msbuild version) instead of dotnet build? dotnet build uses the portable msbuild which has some problems with desktop compiled build tasks...

@ManfredLange
Copy link

ManfredLange commented Sep 19, 2017

@ViktorHofer same issue here but using msbuild instead is not an option as it runs into a different set of problems in a solution of 50+ projects targeting either netstandard2.0 or net461.

Some suggestions say use "dotnet build" instead of msbuild, some other sources suggest the opposite. Problem is none of the two works reliably. Running any of them against a solution file doesn't work at all, so we created our own build tool. It's a big mess from the perspective of a maintainer of old-ish code (net461, old/new csproj file format) and new code (netstandard2.0). It's just sad and disappointing, cause a large amount of wasted time.

No need to reopen this issue. Just need to vent somewhere. :-)

@msftgits msftgits transferred this issue from dotnet/cli Jan 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants