2

I have following ps script:-

function buildVS
{
    param
    (
        [parameter(Mandatory=$true)]
        [String] $path,

        [parameter(Mandatory=$false)]
        [bool] $nuget = $true,

        [parameter(Mandatory=$false)]
        [bool] $clean = $true
    )
    process
    {
        $msBuildExe = 'C:\Program Files (x86)\MSBuild\14.0\Bin\msbuild.exe'

        if ($nuget) {
            Write-Host "Restoring NuGet packages" -foregroundcolor green
            nuget restore "$($path)"
        }

        if ($clean) {
            Write-Host "Cleaning $($path)" -foregroundcolor green
            & "$($msBuildExe)" "$($path)" /t:Clean /m
        }

        Write-Host "Building $($path)" -foregroundcolor green
        & "$($msBuildExe)" "$($path)" /t:Rebuild /m:4 /p:BuildInParallel=true  /langversion:7.2 
    }
}

buildVS .\Backend\Backend.sln $false $true

I can successfully build it by the IDE. I have c# Language version set in my project as 7.2.

I don't know how to set c# language version by command line compiler. I get following error:-

CSC : error CS1617: Invalid option '7.2' for /langversion; must be ISO-1, ISO-2, Default or an integer in range 1 to 6. [C:\dev\Backend\source\dev.csproj] 2>Done Building Project "C:\dev\Backend\source\dev.csproj" (Rebuild target(s)) -- FAILED. 1>Done Building Project "C:\dev\Backend\Backend.sln" (Rebuild target(s)) -- FAILED.

Build FAILED.

   "C:\dev\Backend\Backend.sln" (Rebuild target) (1) ->
   "C:\dev\Backend\source\dev.csproj"

(Rebuild target) (2) -> (CoreCompile target) -> CSC : error CS1617: Invalid option '7.2' for /langversion; must be ISO-1, ISO-2, Default or an integer in range 1 to 6. [C:\dev\Backend\source\dev.csproj]

0 Warning(s)
1 Error(s)

I am trying to minimize the compile time by the script. I have 7/8 solution to build. It is really time-consuming to do it by IDE. If I can build one solution successfully by the script, I will call the same script function with other solutions.

masiboo
  • 4,537
  • 9
  • 75
  • 136
  • Try "latest" or "7" instead of "7.2". https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-options/langversion-compiler-option – Bojan B Feb 07 '18 at 15:18
  • Install msbuild version 15, then try latest as the version. – Equalsk Feb 07 '18 at 15:21
  • msbuild 15, comes in separate installer? In which ide/installer? – masiboo Feb 07 '18 at 15:30
  • I believe it's listed at the bottom as build tools: https://www.visualstudio.com/downloads/ – Equalsk Feb 07 '18 at 15:38
  • I tried msbuild version 15. Also tired /langversion:7 and /langversion:latest. But still same error MSBUILD : error MSB1001: Unknown switch. Switch: /langversion:7 – masiboo Feb 07 '18 at 18:22

1 Answers1

0

You need to use /p:langversion="7.2" instead of /langversion:7.2.

Another thing that you can do is to create a file called Directory.Build.props in the same folder of your .sln file with the following content:

<Project>
  <PropertyGroup>
    <LangVersion>7.2</LangVersion>
  </PropertyGroup>
</Project>

And it should work without the parameter.

artberri
  • 1,327
  • 13
  • 26