16
votes

Since Visual Studio 2017 is released and we can use the new C# 7 features I expected this will work when deploying on Azure Web apps.

Unfortunately we're seeing compile errors when using continuous deployment (kudu git deploy) so it seems Azure doesn't support the new toolchain yet.

Is there anything we can do to get this to work now (besides publishing the assemblies directly)?

3
Are you using a local version of Kudu?DavidG
No, we're simply commiting to Github, which triggers Azure to fetch the changes using Kudu.Robert Massa
Oh, I wonder if they haven't updated to the latest build tools on Azure yet. Can you tell what version of MSBuild is running from the logs?DavidG
Yes, it's running version 14.0. And I've checked the folder (D:\Program Files (x86)\MSBuild), it doesn't contain a newer version.Robert Massa
Can you please share a minimal repro repo? In our tests this was working as the compilers are coming from a NuGet package.David Ebbo

3 Answers

23
votes

since we don't yet have msbuild15 in Azure. if you want to use c#7 features with continuous integration, you may need some workaround

  1. for dotnet core web solution, you can build it in Azure out of the box. (it uses its own dotnet msbuild.dll) [repository sample]
  2. for asp.net web solution, you need to add Microsoft.Net.Compilers 2.0+ nuget package to the project where the new language feature is applied. For example, if a class library in the solution is using the new syntax, you need to add nuget package to that lib project. (the new c# compiler is thus imported if you refer this nuget package) [repository sample]
  3. finally for mixed solution (dotnet core web app + .NET framework class lib), you need to run nuget restore for the .NET framework lib project independently since dotnet restore is not backwards compatible, it cannot retore project from the old build system. I did this by hacking my deploy.cmd [repository sample]

these workarounds either try to
imitate msbuild15 (case1: dotnet msbuild.dll, case2: compiler as a nuget package)
or imitate nuget4.0 (case 3: run both dotnet restore and nuget3.5 restore)

we are in the process of building these tools for Azure, they should be out soon. you can stay updated on github

3
votes

Adding the Microsoft.Net.Compilers NuGet package fixes the issue.

1
votes

As pointed out by @joshuanapoli in a comment to the accepted answer Scenario #2 works only with Microsoft.Net.Compilers v2.4.0 and below.

Took me a couple of hours to notice and figure it out.