0

I am creating test automation for my code generation library. I have a test project in C# 7.2. The project compiles with Visual Studio without any issues. My test is updating the code of this project. Then I want the test to compile the project, load the assembly, and verify it works as expected.

I tried both msbuild and csc. Both are complaining that 7.2 is too high for them.

I guess there should be a way to compile the project with devenv, which is already installed and works perfectly via UI.

Is there?

polina-c
  • 6,245
  • 5
  • 25
  • 36
  • 1
    A [devenv command](https://learn.microsoft.com/en-us/visualstudio/ide/reference/build-devenv-exe?view=vs-2017#example) like this:[devenv SolutionName /Build SolnConfigName /Project ProjName /ProjectConfig ProjConfigName]? – LoLance Mar 27 '19 at 06:11

1 Answers1

3

For C# 7.2 you'll have to use the MSBuild version shipped with VS2017 (Version 15). Assuming that the command line runs on a machine where VS2017 Professional is installed, the correct MSBuild path should be

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe

Any other version of MSBuild should fail to compile C# 7. Specifically, I am building C# 7.2 projects with MSBuild 15.9 and it works.

Edit

You could install MSBuild 15 with the build tools for Visual Studio (see here). I don't know fow sure which version will be installed, but I assume that it'd be the latest. Please note that according to this answer the path will be slightly different.

Paul Kertscher
  • 9,416
  • 5
  • 32
  • 57