Cannot build .Net Core in WSL with mount volume - visual-studio-code

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

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!

Related

The "GenerateResource" task failed unexpectedly when building docker windows image in DevOps

I feel like something has broken in the latest version of mcr.microsoft.com/dotnet/sdk:6.0 as this was working just a few weeks ago, but I thought I'd post here to see if anyone has had similar problems and if there is a fix/workaround.
When trying to build, the following error is thrown
Step 9/18 : RUN dotnet publish "Test.Service.csproj" -c Release -o /app/publish
---> Running in f763996ec9e3
MSBuild version 17.3.0+92e077650 for .NET
Determining projects to restore...
Restored C:\src\Test.Service\Test.Service.csproj (in 15.18 sec).
Restored C:\src\Test.Core\Test.Core.csproj (in 15.18 sec).
Restored C:\src\Test.DataLayer\Test.DataLayer.csproj (in 1.74 sec).
C:\Program Files\dotnet\sdk\6.0.400\Microsoft.Common.CurrentVersion.targets(3262,5): error MSB4018: The "GenerateResource" task failed unexpectedly. [C:\src\Test.DataLayer\Test.DataLayer.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Microsoft.Common.CurrentVersion.targets(3262,5): error MSB4018: System.Runtime.InteropServices.COMException (0x80040154): Retrieving the COM class factory for component with CLSID {7B8A2D94-0AC9-11D1-896C-00C04FB6BFC4} failed due to the following error: 80040154 Class not registered (0x80040154 (REGDB_E_CLASSNOTREG)). [C:\src\Test.DataLayer\Test.DataLayer.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Microsoft.Common.CurrentVersion.targets(3262,5): error MSB4018: at System.RuntimeTypeHandle.AllocateComObject(Void* pClassFactory) [C:\src\Test.DataLayer\Test.DataLayer.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Microsoft.Common.CurrentVersion.targets(3262,5): error MSB4018: at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions) [C:\src\Test.DataLayer\Test.DataLayer.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Microsoft.Common.CurrentVersion.targets(3262,5): error MSB4018: at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions) [C:\src\Test.DataLayer\Test.DataLayer.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Microsoft.Common.CurrentVersion.targets(3262,5): error MSB4018: at System.Activator.CreateInstance(Type type) [C:\src\Test.DataLayer\Test.DataLayer.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Microsoft.Common.CurrentVersion.targets(3262,5): error MSB4018: at Microsoft.Build.Tasks.GenerateResource.IsDangerous(String filename) [C:\src\Test.DataLayer\Test.DataLayer.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Microsoft.Common.CurrentVersion.targets(3262,5): error MSB4018: at Microsoft.Build.Tasks.GenerateResource.Execute() [C:\src\Test.DataLayer\Test.DataLayer.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Microsoft.Common.CurrentVersion.targets(3262,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\src\Test.DataLayer\Test.DataLayer.csproj]
C:\Program Files\dotnet\sdk\6.0.400\Microsoft.Common.CurrentVersion.targets(3262,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [C:\src\Test.DataLayer\Test.DataLayer.csproj]
The command 'cmd /S /C dotnet publish "Test.Service.csproj" -c Release -o /app/publish' returned a non-zero code: 1
Here is the DockerFile:
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["NuGet.Config", "NuGet.Config"]
COPY ["Test.Service/Test.Service.csproj", "Test.Service/"]
COPY ["Test.DataLayer/Test.DataLayer.csproj", "Test.DataLayer/"]
COPY . .
WORKDIR "/src/Test.Service"
FROM build AS publish
RUN dotnet publish "Test.Service.csproj" -c Release -o /app/publish
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS final
WORKDIR /app
EXPOSE 80
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Test.Service.dll"]
Building works when using the ubuntu-latest agent, but I can't make it work using windows-latest. I've also tried windows-2019 with the same problem.
I have the same issue in my Azure pipeline build using a win2022. It just started within the last few weeks. I can build the container locally fine.
Update: I tested removing the .resx file in my project and now it builds fine.
C:\Program Files\dotnet\sdk\6.0.400\Microsoft.Common.CurrentVersion.targets(3262,5): error MSB4018: The "GenerateResource" task failed unexpectedly.
C:\Program Files\dotnet\sdk\6.0.400\Microsoft.Common.CurrentVersion.targets(3262,5): error MSB4018: System.Runtime.InteropServices.COMException (0x80040154): Retrieving the COM class factory for component with CLSID {7B8A2D94-0AC9-11D1-896C-00C04FB6BFC4} failed due to the following error: 80040154 Class not registered (0x80040154 (REGDB_E_CLASSNOTREG)).
For now I'm using FROM mcr.microsoft.com/dotnet/sdk:6.0.200 AS build.
I'm hoping a fix will be released at some point. It should be fixed along with this isue: https://github.com/dotnet/msbuild/issues/7946

How to change CLI arguments of Jest Runner using VSCode

I'm switching from MacOS to Windows WSL2 Ubuntu subsystem.
I want to run a basic Jest test from VSCode, with the JestRunner plugin :
When I click on the "Run" button, it opens a terminal on VSCode (WSL not PowerShell), but it automatically launches this command
vincent#LAPTOP-xxxxx:~/Development/Labomaton/packages/api/node_modules$ node "//wsl$/Ubuntu-20.04/home/vincent/Development/Labomaton/packages/api/node_modules/jest/bin/jest.js"
"//wsl$/Ubuntu-20.04/home/vincent/Development/Labomaton/packages/api/src/user/infrastructure/rest/pipes/create-user-validation.spec.ts"
-t "Register user into Labomaton missing firstname"
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module '/wsl$/Ubuntu-20.04/home/vincent/Development/Labomaton/packages/api/node_modules/jest/bin/jest.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
So I try to run the same command with the correct path to this node module:
vincent#LAPTOP-xxxxx:~/Development/Labomaton/packages/api/node_modules$ node "/home/vincent/Development/Labomaton/packages/api/node_modules/jest/bin/jest.js"
"/home/vincent/Development/Labomaton/packages/api/src/user/infrastructure/rest/pipes/create-user-validation.spec.ts"
-t "Register user into Labomaton missing firstname"
PASS ../src/user/infrastructure/rest/pipes/create-user-validation.spec.ts
Register user into Labomaton
✓ missing firstname (5 ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 2.313 s
My question is: how to change the path as an argument to this VSCode JestRunner feature?

VSCode remote-ssh cant connect to win server 2019

I'm using VSCode remote-ssh extension for development on winserv2016 and it works as intended. We recently switched to winserv2019 and the extension does not work. the error I get in output is
Server failed to start. - Program 'icacls.exe' failed to run: Win32 internal err
> or "Access is denied" 0x5 occurred while reading the console output buffer. Cont
> act Microsoft Customer Support Services.At line:4 char:1
> + icacls $ai_ /reset /Q
I have and admin rights on this machine, does anyone encounter this issue? I've also tried nightly build of VScode and nightly extension. No Success so far.

Why am I getting "Exit code 100 returned from process: file name 'tf'"

I'm using Azure DevOps (visualstudio.com) and trying to get a Linux Build Agent up and running on a local server. This was working previously, but I upgraded the Linux server from Ubuntu 16.04 to 18.04. That broke my previous build agent.
So I removed the previous build agent and installed an up to date one. The new one registered easily, but when I try and run a build, it fails to check out sources.
Anybody know what might cause this problem, or where I can go for help? I don't manage our Azure DevOps. I'm just trying to get the Linux part working as it was.
Edit: I should note that running ./externals/tee/tf produces zero output (and returns with the same 100 code). Maybe it has something to do with java. I'm running Java(TM) SE Runtime Environment (build 12.0.2+10).
##[debug]Evaluating condition for step: 'Checkout'
##[debug]Evaluating: SucceededNode()
##[debug]Evaluating SucceededNode:
##[debug]=> True
##[debug]Result: True
##[section]Starting: Checkout
==============================================================================
Task : Get sources
Description : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.
Version : 1.0.0
Author : Microsoft
Help : [More Information](https://go.microsoft.com/fwlink/?LinkId=798199)
==============================================================================
##[debug]Processed: ##vso[plugininternal.updaterepositorypath alias=__designer_repo;]/home/***/myagent/_work/1/s
##[debug]Repository requires to be placed at '/home/***/myagent/_work/1/s', current location is '/home/***/myagent/_work/1/s'
Prepending PATH environment variable with directory containing 'tf'.
##[debug]Processed: ##vso[task.prependpath]/home/***/myagent/externals/tee
##[debug]PATH: '/home/***/myagent/externals/tee:/home/***/bin:/home/***/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin'
Querying workspace information.
##[debug]tf workspaces -format:xml "-collection:https://mydomain.visualstudio.com/" -jwt:*** -noprompt
##[debug]Starting process:
##[debug] File name: 'tf'
##[debug] Arguments: 'workspaces -format:xml "-collection:https://mydomain.visualstudio.com/" -jwt:*** -noprompt'
##[debug] Working directory: '/home/***/myagent/_work/1/s'
##[debug] Require exit code zero: 'True'
##[debug] Encoding web name: ; code page: ''
##[debug] Force kill process on cancellation: 'False'
##[debug] Redirected STDIN: 'False'
##[debug] Persist current code page: 'False'
##[debug] Keep redirected STDIN open: 'False'
##[debug] High priority process: 'False'
##[debug]Updated oom_score_adj to 500 for PID: 1921.
##[debug]Process started with process id 1921, waiting for process exit.
##[debug]STDOUT/STDERR stream read finished.
##[debug]STDOUT/STDERR stream read finished.
##[debug]Finished process 1921 with exit code 100, and elapsed time 00:00:03.3458546.
##[error]Exit code 100 returned from process: file name 'tf', arguments 'workspaces -format:xml "-collection:https://mydomain.visualstudio.com/" -jwt:*** -noprompt'.
##[debug]Processed: ##vso[task.logissue type=error;]Exit code 100 returned from process: file name 'tf', arguments 'workspaces -format:xml "-collection:https://mydomain.visualstudio.com/" -jwt:*** -noprompt'.
##[debug]Processed: ##vso[task.complete result=Failed;]
##[debug] at Agent.Plugins.Repository.TeeCliManager.WorkspacesAsync(Boolean matchWorkspaceNameOnAnyComputer)
at Agent.Plugins.Repository.TfsVCSourceProvider.GetSourceAsync(AgentTaskPluginExecutionContext executionContext, RepositoryResource repository, CancellationToken cancellationToken)
at Agent.Plugins.Repository.CheckoutTask.RunAsync(AgentTaskPluginExecutionContext executionContext, CancellationToken token)
at Agent.PluginHost.Program.Main(String[] args)
##[section]Finishing: Checkout
When I saw that the tf command produced no output, I was pretty sure it had to be a java problem. I had tried many different versions of java and none of them worked. But with Oracle java 1.8.0_221 it finally worked.
I downloaded the .tar.gz file, extracted it, and overwrote the /usr/bin/java* symlinks to point to the 1.8 copies and then it worked.

Chain psexec and nunit is not working (psexec exit with code 1 and nunit is crashed)

Sorry for unclear subject but i really don't understand where problem.
I use a system for autotests c#+webdriver for chrome + nunit (2.6) + cc.net ( 1.6.7981.1)
And my tests is run on remote machine (Windows XP SP 2 x86)via psexec which start bat file on remote machine
bat file includes 2 commands:
run msbuild
run nunit-console
Well, psexec has next arguments
/accepteula \MachineName -u Login -p Pass -s Path\start.bat
Bat file has next command
nunit-console-x86.exe "%PROJECT_FOLDER%\Path\Tests.dll" "/xml=%TEST_RESULT_PATH%"
When cc.net launch psexec tests is started and the tests work during some time. Unexpected, psexec exit with code 1
message level="Error">Path\start.bat exited on MachineName with error code 1. message
But nunit-console on remote machine is continue working
And after some time console is crashed with error
szAppName : nunit-console-x86.exe szAppVer : 2.6.0.12051
szModName : kernel32.dll szModVer : 5.1.2600.2180 offset :
0001eb33
Message from Event log
Application: nunit-console-x86.exe Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.IOException Stack: at
System.IO._Error.WinIOError(Int32, System.String) at
System.IO._ConsoleStream.Write(Byte[], Int32, Int32) at
System.IO.StreamWriter.Flush(Boolean, Boolean) at
System.IO.StreamWriter.Write(Char[], Int32, Int32) at
System.IO.TextWriter.WriteLine(System.String) at
System.IO.TextWriter.WriteLine(System.String, System.Object) at
System.IO.TextWriter+SyncTextWriter.WriteLine(System.String,
System.Object) at System.Console.WriteLine(System.String,
System.Object) at NUnit.ConsoleRunner.Runner.Main(System.String[])
at NUnit.ConsoleRunner.Class1.Main(System.String[])
If run nunit locally than no problem(nunit-console works fun).
Some time ago system worked, and i don't know what is changed (This is most bad case)
How can i resolve this problem?
Thanks!
This problem is resolved!
Now system is working