我在 Visual Studio 2022 17.9.2 中遇到 Workflow Foundation 设计器和 SDK 样式 csproj 的问题。
假设我们有 3 个 .net 4.8 工作项目
设计器和运行时 WorkflowApplication 都可以工作,没什么特别的。
现在我们将两个 ActivityLibrary 项目移植到 SDK 样式(我手动尝试并使用升级助手,得到了类似的结果)
(ActivityLibrary1.csproj 和 ActivityLibrary2.csproj 仅在引用和 Activity1/Activity2 上有所不同)
<Project Sdk="Microsoft.NET.Sdk" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<OutputType>Library</OutputType>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<LanguageTargets Condition="Exists('$(MSBuildProjectDirectory)\$(AssemblyName).csproj')">$(MSBuildToolsPath)\Microsoft.CSharp.targets</LanguageTargets>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ActivityLibrary2\ActivityLibrary2.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Activities" />
<Reference Include="System.Xaml" />
</ItemGroup>
<ItemGroup>
<XamlAppdef Include="Activity1.xaml">
<Generator>MSBuild:Compile</Generator>
</XamlAppdef>
</ItemGroup>
</Project>
然后重建解决方案并打开 Activity1.xaml。
<Activity mc:Ignorable="sap sap2010 sads" x:Class="ActivityLibrary1.Activity1"
sap2010:ExpressionActivityEditor.ExpressionActivityEditor="C#"
sap2010:WorkflowViewState.IdRef="ActivityLibrary1.Activity1_1"
xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sads="http://schemas.microsoft.com/netfx/2010/xaml/activities/debugger"
xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation"
xmlns:sap2010="http://schemas.microsoft.com/netfx/2010/xaml/activities/presentation"
xmlns:sco="clr-namespace:System.Collections.ObjectModel;assembly=mscorlib"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<TextExpression.NamespacesForImplementation>
<sco:Collection x:TypeArguments="x:String">
<x:String>System</x:String>
<x:String>System.Collections.Generic</x:String>
<x:String>System.Data</x:String>
<x:String>System.Linq</x:String>
<x:String>System.Text</x:String>
</sco:Collection>
</TextExpression.NamespacesForImplementation>
<TextExpression.ReferencesForImplementation>
<sco:Collection x:TypeArguments="AssemblyReference">
<AssemblyReference>mscorlib</AssemblyReference>
<AssemblyReference>System</AssemblyReference>
<AssemblyReference>System.Core</AssemblyReference>
<AssemblyReference>System.Data</AssemblyReference>
<AssemblyReference>System.ServiceModel</AssemblyReference>
<AssemblyReference>System.Xml</AssemblyReference>
<AssemblyReference>System.Xml.Linq</AssemblyReference>
<AssemblyReference>ActivityLibrary1</AssemblyReference>
</sco:Collection>
</TextExpression.ReferencesForImplementation>
<WriteLine sap2010:WorkflowViewState.IdRef="WriteLine_1" sads:DebugSymbol.Symbol="d01DOlxVc2Vyc1xtYXR0ZW9cc291cmNlXHJlcG9zXEFjdGl2aXR5TGlicmFyeTFcQWN0aXZpdHlMaWJyYXJ5MVxBY3Rpdml0eTEueGFtbAEfAx9xAgEB" />
<sap2010:WorkflowViewState.ViewStateManager>
<sap2010:ViewStateManager>
<sap2010:ViewStateData Id="WriteLine_1" sap:VirtualizedContainerService.HintSize="210,62" />
<sap2010:ViewStateData Id="ActivityLibrary1.Activity1_1" sap:VirtualizedContainerService.HintSize="250,142" />
</sap2010:ViewStateManager>
</sap2010:WorkflowViewState.ViewStateManager>
</Activity>
设计器打开了,但问题是:
任何帮助将不胜感激,谢谢。
备注:
<AssemblyReference>System.Data</AssemblyReference>
<AssemblyReference>System.Core</AssemblyReference>
成为
<AssemblyReference>System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</AssemblyReference>
<AssemblyReference>System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</AssemblyReference>
非 SDK 风格的 csproj 从未发生过这种情况
<WriteLine sap2010:WorkflowViewState.IdRef="WriteLine_1">
<InArgument x:TypeArguments="x:String">
<mca:CSharpValue x:TypeArguments="x:String">typeof(ActivityLibrary1.Activity1).FullName</mca:CSharpValue>
</InArgument>
<sads:DebugSymbol.Symbol>d01DOlxVc2Vyc1xtYXR0ZW9cc291cmNlXHJlcG9zXEFjdGl2aXR5TGlicmFyeTFcQWN0aXZpdHlMaWJyYXJ5MVxBY3Rpdml0eTEueGFtbAImAysPAgEBKAcocAIBAg==</sads:DebugSymbol.Symbol>
</WriteLine>
工作流程打开,表达式仍然存在,但如果我从设计器更改它,它将恢复为我在手动 xaml 更新期间设置的值。
C:\Solution\ActivityLibrary1\obj\Debug
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8
C:\Solution\ActivityLibrary2\bin\Debug\
C:\Solution\ActivityLibrary1\bin\Debug\
如果在 sdk 样式的 csproj 中打开
C:\Solution\ActivityLibrary1\obj\Debug\net48
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8
C:\Solution\ActivityLibrary2\bin\Debug\net48
file:\C:\Windows\Microsoft.NET\Framework64\v4.0.30319
所以看起来缺少
C:\Solution\ActivityLibrary1\bin\Debug\
并添加 file:\C:\Windows\Microsoft.NET\Framework64\v4.0.30319
路径:我尝试手动将 ActivityLibrary2 和 Newtonsoft.Json dll 复制到但没有任何变化。
我转载:WriteLine C# 表达式中写的任何表达式都不保留
请在开发者社区报告问题并在此发布链接,以便我们跟进。