16

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)?

Robert Massa
  • 4,345
  • 1
  • 32
  • 44
  • Are you using a local version of Kudu? – DavidG Mar 28 '17 at 14:06
  • No, we're simply commiting to Github, which triggers Azure to fetch the changes using Kudu. – Robert Massa Mar 28 '17 at 14:11
  • 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 Mar 28 '17 at 14:19
  • 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 Mar 28 '17 at 14:20
  • 1
    Can you please [share a minimal repro repo](https://github.com/projectkudu/kudu/wiki/Using-a-git-repo-to-report-an-issue)? In our tests this was working as the compilers are coming from a NuGet package. – David Ebbo Mar 28 '17 at 14:29
  • What's the package? I'll check to see if we have it. This is a solution that was created in VS2015, later opened in '17 where some C# 7 code was added. Locally it builds in '17, but not '15. – Robert Massa Mar 28 '17 at 14:32
  • Adding the `Microsoft.Net.Compilers` NuGet package fixed the issue. Thanks! – Robert Massa Mar 28 '17 at 14:39
  • You try to help then the guy who writes the product comes along and gazumps you! :) I suggest adding that as an answer btw, it might help future people. – DavidG Mar 28 '17 at 14:58

3 Answers3

23

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

watashiSHUN
  • 9,684
  • 4
  • 36
  • 44
  • Adding Microsoft.Net.Compilers solves the problem... but slows down dramatically the builds!! It's frustrating :( – Subgurim May 24 '17 at 18:20
  • 1
    @Subgurim msbuild-15.3-preview is already in Azure west us2, this building tools will soon be available everywhere – watashiSHUN May 24 '17 at 23:55
  • Great! I wish it would be announced properly ;) – Subgurim May 25 '17 at 12:15
  • 6
    Scenario #2 works for me with Microsoft.Net.Compilers v2.4.0, but not v2.6.0 (I still see an error about lack of MSBuild 15). – joshuanapoli Dec 14 '17 at 17:55
  • My deployments are failing because MSBuild is being detected as v14 instead of v15. The error is releated to using the element in the project file `Error MSB4066: The attribute "Version" in element is unrecognized` – Aaron Hudon Jun 10 '18 at 18:45
  • 3
    @joshuanapoli Thanks for the tip. Spent about 3 hours trying to get Kudu to deploy my app today; I downgraded Microsoft.Net.Compilers v.2.10.0 to 2.4.0 and it succeeded. watashiSHUN - any idea why it's necessary to downgrade this nuget package to get this to work on a brand new azure app service plan to get kudu to build a .net 4.7 using c# 7 tuples? – pettys Jan 04 '19 at 05:53
3

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

Robert Massa
  • 4,345
  • 1
  • 32
  • 44
  • "[You need to install Microsoft.Net.Compilers 2.0+ nupkg in order to support C# 7.0 features.](http://stackoverflow.com/questions/42216740/c-sharp-7-features-dont-work-within-a-web-project-on-visual-studio-2017-rc)" – watashiSHUN Mar 28 '17 at 21:12
  • @watashiSHUN That's not the same thing. c# 7 features worked without issue in VS2017, only when deploying a problem occurred. – Robert Massa Mar 29 '17 at 08:51
  • 2
    This is not working for me if deploying from deployment from github – Jonathan Mar 29 '17 at 19:44
  • What's the error message? We're also deploying from Github and this fixed it for me. – Robert Massa Mar 30 '17 at 07:49
  • For "classic .NET" (in my case targeting .NET 4.5) adding `Microsoft.Net.Compilers` seems to do the trick – but please note that ALL projects that use C# 7 syntax need to have the package added, adding it to the web project only is not enough – mookid8000 Mar 31 '17 at 05:17
1

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.

apostolov
  • 1,646
  • 16
  • 20