dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.88k stars 4.01k forks source link

Windows Workflow Service Won't Compile With C# 7.0+ Language Features #27018

Open vsfeedback opened 6 years ago

vsfeedback commented 6 years ago

Upgrading a legacy service from 4.5.1 to 4.7.2, C# 7.2 (latest minor language). Updated the target language version and .NET target framework

Application builds when commenting out the CSPROJ lines: <Import Project="$(MSBuildToolsPath)\Workflow.Targets" />

However, when Workflow targets are enabled, I am unable to do specific to C# 7.0 inline out declaration: int.tryparse(s, out int output);

Have to revert code back to: int output = 0; int.tryparse(s, out output);

Sample Errors: C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Workflow.targets(121,5): error : Invalid expression term 'int' C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Workflow.targets(121,5): error : ; expected C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Workflow.targets(121,5): error : Invalid expression term ')'

This issue has been moved from https://developercommunity.visualstudio.com/content/problem/246478/windows-workflow-service-wont-compile-with-c-70-la.html VSTS ticketId: 611928 These are the original issue comments: (no comments) These are the original issue solutions: (no solutions)

houseofcat commented 6 years ago

Let me know if you guys need any new infos and thank you for looking at this.

jcouv commented 6 years ago

@rainersigwald Would you know who owns Workflow.targets? It seems it's invoking the C# compiler but not passing LangVersion through properly.

rainersigwald commented 6 years ago

The MSBuild-repo instance of that file just redirects to one distributed with the .NET Framework in C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Workflow.targets.

That file has

<UsingTask TaskName="System.Workflow.ComponentModel.Compiler.CompileWorkflowTask" AssemblyName="System.Workflow.ComponentModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

I think the source for that is here (internal link).

It looks like that uses CodeDOM, which I don't think has been enlightened about C# 7.2. And the task code hasn't changed in many, many years.

I also don't see an import of Workflow.targets in a brand-new project with the "WCF Workflow Service Application" template, so I wonder if there's a "more modern" set of imports to build such a service.

@jcouv I'll try to help you find the right owners offline.

dmetzgar commented 6 years ago

System.Workflow* assemblies are for v1 workflows, which are deprecated. The Workflow.targets file executes tasks that use CodeDom to build a partial class that goes with the code-behind for the workflow. If CodeDom is no longer available in C# 7.2, then v1 workflows will not work.

@rainersigwald, the new "WCF Workflow Service Application" project you created is using v2 workflows, which are the System.Activities* assemblies. These use System.Xaml to create types instead of CodeDom. V2 workflows have a different set of MSBuild targets and tasks.

In VS2017, only v2 workflow templates are included. We were unable to completely remove v1 workflow because of SharePoint 2010 workflow tooling support. Customers that install the Office/SharePoint tools can still open v1 workflow projects, they just can't create new ones.