Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot build .Net Core in WSL with mount volume

Describe the bug

I am using VS Code, WSL and .net core 3.0 preview to build one sample web API project in WSL that is stored in C drive. But It throws an exception with a strange error

"/mnt/c/temp/test/test.csproj" (default target) (1:7) ->
                   (_CreateAppHost target) ->
                     /usr/share/dotnet/sdk/3.0.100-preview9-014004/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018: The "CreateAppHost" task failed unexpectedly. [/mnt/c/temp/test/test.csproj]
                   /usr/share/dotnet/sdk/3.0.100-preview9-014004/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018: System.IO.IOException: Invalid argument [/mnt/c/temp/test/test.csproj]
                   /usr/share/dotnet/sdk/3.0.100-preview9-014004/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at System.IO.MemoryMappedFiles.MemoryMappedView.CreateView(SafeMemoryMappedFileHandle memMappedFileHandle, MemoryMappedFileAccess access, Int64 requestedOffset, Int64 requestedSize) [/mnt/c/temp/test/test.csproj]
                   /usr/share/dotnet/sdk/3.0.100-preview9-014004/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at System.IO.MemoryMappedFiles.MemoryMappedFile.CreateViewAccessor(Int64 offset, Int64 size, MemoryMappedFileAccess access) [/mnt/c/temp/test/test.csproj]
                   /usr/share/dotnet/sdk/3.0.100-preview9-014004/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at Microsoft.NET.HostModel.AppHost.HostWriter.<>c__DisplayClass2_0.<CreateAppHost>g__RewriteAppHost|0() [/mnt/c/temp/test/test.csproj]
                   /usr/share/dotnet/sdk/3.0.100-preview9-014004/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at Microsoft.NET.HostModel.RetryUtil.RetryOnIOError(Action func) [/mnt/c/temp/test/test.csproj]
                   /usr/share/dotnet/sdk/3.0.100-preview9-014004/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at Microsoft.NET.HostModel.AppHost.HostWriter.CreateAppHost(String appHostSourceFilePath, String appHostDestinationFilePath, String appBinaryFilePath, Boolean windowsGraphicalUserInterface, String assemblyToCopyResorcesFrom) [/mnt/c/temp/test/test.csproj]
                   /usr/share/dotnet/sdk/3.0.100-preview9-014004/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at Microsoft.NET.Build.Tasks.CreateAppHost.ExecuteCore() in /_/src/Tasks/Microsoft.NET.Build.Tasks/CreateAppHost.cs:line 68 [/mnt/c/temp/test/test.csproj]
                   /usr/share/dotnet/sdk/3.0.100-preview9-014004/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at Microsoft.NET.Build.Tasks.TaskBase.Execute() in /_/src/Tasks/Common/TaskBase.cs:line 38 [/mnt/c/temp/test/test.csproj]
                   /usr/share/dotnet/sdk/3.0.100-preview9-014004/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [/mnt/c/temp/test/test.csproj]
                   /usr/share/dotnet/sdk/3.0.100-preview9-014004/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(370,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [/mnt/c/temp/test/test.csproj]

To Reproduce

Steps to reproduce the behavior: 1. Using this version of ASP.NET Core '3.0.100-preview9' both on Window 10 and WSL 2. In Window 10 + cd c:\temp + dotnet new webapi 3. Go to WSL, (/mnt/c/temp) 3. Run dotnet build 4. See error

Expected behavior

Run "dotnet build" successfully and can run/debug application in WSL from VSCode

like image 993
Jacky Phuong Avatar asked Sep 21 '19 04:09

Jacky Phuong


1 Answers

Setting up dotnet on a fresh installation of Ubuntu (20.04) under WSL 2 on Windows 10 I had the above The "CreateAppHost" task failed unexpectedly. error along with a bunch file-system related permission errors when running dotnet build - however sudo dotnet build worked just fine...

My solution was to close/restart all running WSL instances, from a windows command prompt list all running instances;

C:\> wsl -l --running
Windows Subsystem for Linux Distributions:
docker-desktop-data (Default)
Ubuntu
docker-desktop

Then close the running one you wish to use for dotnet;

C:\> wsl --terminate Ubuntu

And then re-run/re-start the distro;

C:\> wsl -d Ubuntu

And then by magic dotnet build worked without the addition of sudo and also worked via vscode WSL remote plugin... hopefully this simple 'reboot solution' helps someone else!

like image 147
alv Avatar answered Oct 12 '22 05:10

alv