Force MSBuild 14.0 in psake build for C# 6.0 code base
Asked Answered
E

2

12

I recently updated to Visual Studio 2015 and am using the new C# 6.0 features. In VS, everything builds correctly.

However, I use PSake as build script language, and the build always fails at places where I use c# 6.0 features. How can I tell psake to use MSBuild 14.0, so that the new c# 6.0 features build correctly?

Tried & failed:

  • Passing in the framework version to psake: Unknown .NET Framework version, 4.6

  • Call the vsvars32.bat of VS2015 prior to invoking psake. PSake still uses the old MSBuild version.

Essequibo answered 8/10, 2015 at 11:34 Comment(0)
S
16

I had the same issue & fixed it by configuring PSake build script to use .Net Framework 4.6, simply by adding Framework "4.6" in the beginning of the file. You may check this unit test from PSake code base dotNet4.6_should_pass.ps1

Sepulchre answered 12/10, 2015 at 1:10 Comment(2)
Thanks, this seems to be the preferred way. Unfortunately it doesn't work on my machine. But I found a workaround, I'll post it as another answer here shortly.Essequibo
Or use the -framework parameter when calling psake.ps1Pandiculation
E
3

The solution described by @WahidShalaly seems to be the correct one, so use that. However, on my machine it still didn't find the correct MSBuild version so here is the workaround that I have in place instead:

Add the following task to your PSake script:

Task SetEnvironment {
  Exec { & $env:VS140COMNTOOLS\vsvars32.bat }
}

This sets the environment for VS2015 compilation from within PSake.

Now add a dependency to SetEnvironment from every task that calls MSBuild and use msBuild.exe instead of just msbuild. Example:

Task Compile -Depends SetEnvironment {
  Exec { & "msbuild.exe" "theSolution.sln" /p:VisualStudioVersion=14.0 }
}
Essequibo answered 12/10, 2015 at 7:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.