msbuild icon indicating copy to clipboard operation
msbuild copied to clipboard

[MONO] Path for external source file in inline task isn't resolved

Open gotmachine opened this issue 7 years ago • 6 comments

Steps to reproduce

Create an inline task with UsingTask and use an external file for the source code like this :

<Code Type="class" Language="cs" Source="..\..\mytasksource.cs" />

Then call the task from MSBuild.exe in windows and MSBuild in linux

Expected behavior

On Microsoft (R) Build Engine version 16.2.37902+b5aaefc9f pour .NET Framework (Win10)
The path to the source file is correctly resolved and everything is fine.

Actual behavior

On Microsoft (R) Build Engine version 16.0.0.0 for Mono (Ubuntu 18.04 + Mono 6.0) The path to the source file is not resolved, it seems to be added to the current path without any combine operation. This is the error I'm getting (edited for readability) :

/mnt/c/[...](435,5): error MSB4175: The task factory "CodeTaskFactory" could not be loaded 
from the assembly "/usr/lib/mono/msbuild/Current/bin/Microsoft.Build.Tasks.Core.dll". 
Could not find file "/mnt/c/[--path to the csproj folder--]/..\..\mytasksource.cs" 
[/mnt/c/[--path to the csproj folder--]/mycsproj.csproj]

EDIT : Note that if I place the "mytasksource.cs" file in the same folder as "mycsproj.csproj" and change my task definition to : <Code Type="class" Language="cs" Source="mytasksource.cs" /> the task run fine on the mono MSBuild.

And sorry if this is not the place for issues about the mono version of MSBuild.

gotmachine avatar Aug 13 '19 19:08 gotmachine

@radical should this go into the mono/msbuild repo?

livarcocc avatar Aug 14 '19 18:08 livarcocc

@livarcocc mono/MSBuild doesn't have its own issue tracking at the moment.

rainersigwald avatar Aug 14 '19 18:08 rainersigwald

@gotmachine One possible workaround to investigate: try using RoslynCodeTaskFactory instead of CodeTaskFactory.

rainersigwald avatar Aug 14 '19 18:08 rainersigwald

Thanks for the answers. I confirm that the problem also happen on OSX with mono.

I would like to try the RoslynCodeTaskFactory workaround but I'm having trouble making it work. It seems the way to use it is by doing :

<UsingTask TaskName="UploadGitHubRelease" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildBinPath)\Microsoft.Build.Tasks.Core.dll" >

However (sorry for the unrelated question, but the documentation for all this is kinda sparse) when I do that it seems the references include...

<Task>
  <Reference Include="System.Net.Http" />
  [...]
  <Code Type="class" Language="cs" Source="$(UtilityPath)\UploadGitHubRelease.cs" />
</Task>

... doesn't have access to the full framework. I'm getting a bunch of :

error MSB3755: cannot found "System.Net.Http".

How do I use the RoslynCodeTaskFactory with (cross-platform) references to the full .NET framework ?

Edit : I'm also getting a : error MSB4175: Cannot load task factory "RoslynCodeTaskFactory" from [...]\ Microsoft.Build.Tasks.Core.dll". The task factory must return a value for the property " TaskType"

Note : $(MSBuildBinPath)\Microsoft.Build.Tasks.Core.dll is present on my system.

Edit2 : Well I guess it's that issue : https://github.com/microsoft/msbuild/issues/3726

Edit3 : Err, found the workaround, mentioned in https://github.com/microsoft/msbuild/issues/4390 :

Remove the <Reference Include="System.[*]" /> when using RoslynCodeTaskFactory. These things (or at least more examples covering these topics) really should be mentioned here : RoslynCodeTaskFactory MS docs

Edit4 : So, RoslynCodeTaskFactory works on windows, but not on linux. I'm getting MSB3755: Could not find reference "mscorlib" and same for error with with netstandard

tl;dr Can't test right now if using RoslynCodeTaskFactory resolves the initial issue, will update this when I do.

gotmachine avatar Aug 17 '19 09:08 gotmachine

Ok, can't make the class to run with RoslynCodeTaskFactory on mono, but anyway the error in my "edit4" comes after the path resolution error, so in definitive :

The path specified in <Code Source="..\mycode.cs" /> isn't resolved on Linux/OSX with MSBuild 16.0 for Mono 6.0, no matter if I use RoslynCodeTaskFactory or CodeTaskFactory .

It doesn't resolve the .. and it doesn't convert the \ to /.

gotmachine avatar Aug 17 '19 10:08 gotmachine

I just had the same problem. The workaround is to change all your \ to / in the source path. Windows will correctly understand it (even if it's a mix of both \ and / in the same path), and Linux/Mono will see all forward-slashes and be happy. Example that worked for me: <Code Type="Class" Language="cs" Source="$(MSBuildThisFileDirectory)..\BuildTasks\ConfigureFile\ConfigureFile.cs" /> became <Code Type="Class" Language="cs" Source="$(MSBuildThisFileDirectory)../BuildTasks/ConfigureFile/ConfigureFile.cs" /> and I run this on Windows with Visual Studio 2019 16.5, and on Ubuntu 18.04 with Mono 5.12.

RoguePointer80 avatar May 07 '20 15:05 RoguePointer80