0

I tried to switch from Visual Studio to Visual Studio Code with my CORE project. I can build the C# project in Visual Studio without any problems. When I tried VSCode, I see that I need to define tasks. Fortunately, VSCode offers default tasks definition (it generates tasks.json) for me, so I tried them (there are variants for CORE and .NET, as I understand). But both don't work. I tried to make build from command line, but get error (I translate the error to English, it's not original text):

C:\Program Files\dotnet\sdk\2.1.700\Microsoft.Common.CurrentVersion.targets(3046,5): error MSB4216: can not execute task "GenerateResource", because MSBuild cannot create tasks server with execution environment "CLR4" and architecture "x86" or to connect to it. Verify that, (1) required execution environment and architecture do exist and (2) required executable file "C:\Program Files\dotnet\sdk\2.1.700\MSBuild.exe" exists and can be ran. [D:\prj\...\Test.csproj]

and when I tried to find MSBuild.exe in this folder, I found MSBuild.dll only, no any MSBuild.exe. So, I tried to run it with dotnet after entering this folder - it works. But if I try to call dotnet build or to run it with full path to MSBuild.dll from my project folder, I always get this error. Seems, that dotnet command calls MSBuild.dll multiple times and always hit this problem. May be I should setup some paths or similar. But where to do it (without to break ability to build the project in Visual Studio)? What is the convenient way to build CORE projects in Visual Studio Code? How to build them in command line?

PS. May be all documentation which I found was outdated...

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
RandomB
  • 3,367
  • 19
  • 30
  • Possible duplicate of [Build .NET Core console application to output an EXE?](https://stackoverflow.com/questions/44074121/build-net-core-console-application-to-output-an-exe) – Cid Jul 12 '19 at 06:11
  • Can you share your csproj file? Are you using resx files? This should have been fixed in a .NET SDK update which should set `GenerateResourceMSBuildRuntime` and `GenerateResourceMSBuildArchitecture` – Martin Ullrich Jul 12 '19 at 07:21
  • 2
    Why not just build them by msbuild command-line? It seems that you've installed both VS and VS code in machine, you can open [Developer command prompt for VS](https://docs.microsoft.com/en-us/dotnet/framework/tools/developer-command-prompt-for-vs) in `windows start menu`, then use a simple command like `msbuild xx.csproj -p:Configuration=Release` (You've mentioned it works when building in VS) to build .net core project. Or use [build tools for vs package](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=BuildTools&rel=16) to get msbuild.exe if no vs installed. – LoLance Jul 12 '19 at 07:52
  • Does your solution contains a WPF project? – Andrew Jul 12 '19 at 09:59
  • @Andrew yes, true. does it matter? – RandomB Jul 12 '19 at 10:28
  • 1
    @Paul-AG check this: https://github.com/JetBrains/teamcity-dotnet-plugin/issues/105#issuecomment-342801794 – Andrew Jul 12 '19 at 10:31
  • oh, looks like my error. – RandomB Jul 12 '19 at 14:24
  • @LanceLi-MSFT yes, it works! So, how to 1) call it from Visual Studio Code tasks? 2) is it possible to build such projects without VsDevCmd.bat but from Visual Studio Code? – RandomB Jul 12 '19 at 17:22
  • OK, looks I found it - http://www.cazzulino.com/code-developer-command-prompt.html but still don't understand how to configure VSCode tasks – RandomB Jul 12 '19 at 17:41
  • Not familiar with vs code but maybe you can get some help from [this thread](https://stackoverflow.com/questions/48350143/in-visual-studio-code-2017-msbuild-the-term-msbuild-is-not-recognized-as-th). And I'm not sure why you want VsDevCmd.bat, or you can choose to find path of msbuild.exe using `where msbuild` command in develop command prompt for vs, and then call it in VS code. – LoLance Jul 12 '19 at 19:36
  • > why you want... I found path, it is msbuild.dll, I called it with dotnet, but it always raises me the same error, so I suppose problem is with environment variables. I opened the bat-file and it contains a lot of env. vars and so on. IMHO solution may be to replace call of cmd.exe in the bat-file with msbuild.dll only. – RandomB Jul 13 '19 at 03:38

0 Answers0