Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Projects with workflow XAML do not compile #5252

Open
DzonnyDZ opened this issue Aug 6, 2019 · 8 comments
Open

Projects with workflow XAML do not compile #5252

DzonnyDZ opened this issue Aug 6, 2019 · 8 comments
Labels
Feature-XAML Features related to the XAML designer and display and manipulation of XAML files. Parity-Legacy-Feature Missing features from the legacy project system. Triage-Approved Reviewed and prioritized
Milestone

Comments

@DzonnyDZ
Copy link

DzonnyDZ commented Aug 6, 2019

Visual Studio Version: 16.2.0

Summary: Compiling project with XAML Service references fails with The target "CoreCompile" does not exist in the project.

Steps to Reproduce:

  1. Have a project with XAML service references (.xaml file with Build Action: Workflow definition, Custom Tool: MSBuild:Compile) or (.svcmap file with Custom Tool: Xaml Activity Generator which generates .xaml files with Build Action: XamlAppDef and Custom Tool: XamlIntelliSenseFileGenerator)

  2. Convert this project to new project format

  3. Rebuild the project

Expected Behavior: Works, works always and works on first attempt

Actual Behavior: Build fails with error C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Xaml.targets(333,43): error MSB4057: The target "CoreCompile" does not exist in the project.
The build works if you do Rebuild + Build (i.e. 2nd time)

User Impact: Cannot convert projects with such files to new .csproj format. Cannot use new .csproj format consistently.
This si especially issue for compiling such projects on build servers as locally it can be worked around by building the project twice.

More info:
As has already been discussed on #1467 under some circumstances projects containing .xaml files are build using 2-pass build. A temporary projects with extension .tmp_proj is generated and built in order to obtain some kind of reference assembly for the 2nd build (of the main .csproj project). Unfortunately the choice of extension (which is hard-coded in the task) confuses the new project system as it cannot determine from the .tmp_proj extension which language the project is (VB, C# or something else) and thus just some default common options are available. Specifying <LanguageTargets> (<LanguageTargets>$(MSBuildToolsPath)\Microsoft.CSharp.targets</LanguageTargets>) does not solve the issue, just brings bunch error messages like

  • obj\Debug\net472\1ny23niw.AssemblyInfo.cs(14,12,14,18): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
  • obj\Debug\net472\1ny23niw.AssemblyInfo.cs(14,55,14,76): error CS0518: Predefined type 'System.String' is not defined or imported
  • Service References\ChannelScheduleService\Reference.cs(182,6,182,12): error CS0518: Predefined type 'System.Object' is not defined or imported
  • Service References\LookupService\Reference.cs(15,6,15,12): error CS0518: Predefined type 'System.Enum' is not defined or imported
  • Service References\ReferenceDataService\Reference.cs(2642,156,2642,157): error CS0518: Predefined type 'System.Int32' is not defined or imported
  • Service References\ReferenceDataService\Reference.cs(2642,150,2642,155): error CS0246: The type or namespace name 'Order' could not be found (are you missing a using directive or an assembly reference?)
  • Service References\ChannelScheduleService\Reference.cs(15,51,15,60): error CS0246: The type or namespace name 'Namespace' could not be found (are you missing a using directive or an assembly reference?)
  • etc.

Workaround:
As I have observer that in case I do Rebuild + Build in Visual Studio the 2nd build passed, it seems to be possible to work around this issue by doing exactly that: Before build of the offending project try to build it and ignore any build errors. This can be achieved by following MSBuild code in the new .csproj file:

    <Target Name="PreCompileSelf" BeforeTargets="XamlTemporaryAssemblyGeneration" Condition="'$(MSBuildProjectExtension)' == '.csproj' and '$(SelfPreCompile)' != 'true'">
        <Message Text="Pre-compiling $(MSBuildProjectFile)..." Importance="high"/>
        <MSBuild Projects="$(MSBuildProjectFile)" Properties="Configuration=$(Configuration);Platform=$(Platform);SelfPreCompile=true" ContinueOnError="WarnAndContinue"/>
    </Target>
    <Target Name="CoreCompile" Condition="'$(MSBuildProjectExtension)' != '.csproj'">
        <!--Fake target - workaround for 2-phases build of projects with XAML files-->
        <Message Text="CoreCompile target called"/>
    </Target>
@davkean
Copy link
Member

davkean commented Aug 7, 2019

@davidwengier Can you figure out if this is just Workflow XAML, or does it affect WPF too?

@davkean davkean added the Feature-XAML Features related to the XAML designer and display and manipulation of XAML files. label Aug 7, 2019
@davkean davkean added this to the 16.3 milestone Aug 7, 2019
@davkean davkean added the Bug label Aug 7, 2019
@davidwengier
Copy link
Contributor

From my research these are all Worflow related items.

@davidwengier davidwengier modified the milestones: 16.3, Backlog Aug 22, 2019
@DzonnyDZ
Copy link
Author

See dotnet/msbuild#2798

@davkean davkean added Triage-Approved Reviewed and prioritized Parity-Legacy-Feature Missing features from the legacy project system. labels Jan 17, 2020
@davkean davkean changed the title Xaml 2 Pass compilation does not work Projects with workflow XAML do not compile Jan 17, 2020
@danielmeza
Copy link

@DzonnyDZ I try to use your workaround but not work.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net472</TargetFramework>
    <OutputType>Exe</OutputType>
    <StartupObject />
  </PropertyGroup>
  <ItemGroup>
    <None Remove="Activity2.xaml" />
    <None Remove="Workflow1.xaml" />
  </ItemGroup>
  <ItemGroup>
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System" />
    <Reference Include="System.Activities" />
    <Reference Include="System.Core" />
    <Reference Include="System.Data" />
    <Reference Include="System.Runtime.Serialization" />
    <Reference Include="System.ServiceModel" />
    <Reference Include="System.ServiceModel.Activities" />
    <Reference Include="System.Xaml" />
    <Reference Include="System.Xml" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="WindowsBase" />
  </ItemGroup>
  <ItemGroup>
    <XamlAppDef Include="Activity2.xaml">
      <Generator>MSBuild:Compile</Generator>
    </XamlAppDef>
    <XamlAppDef Include="Workflow1.xaml">
      <Generator>MSBuild:Compile</Generator>
    </XamlAppDef>
  </ItemGroup>
  <Choose>
    <When Condition="'$(MSBuildProjectExtension)' != '.csproj' and '$(MSBuildProjectExtension)' != '.vbproj'">
      <PropertyGroup>
        <LanguageTargets Condition="Exists('$(MSBuildProjectDirectory)\$(AssemblyName).csproj')">$(MSBuildToolsPath)\Microsoft.CSharp.targets</LanguageTargets>
        <LanguageTargets Condition="Exists('$(MSBuildProjectDirectory)\$(AssemblyName).vbproj')">$(MSBuildToolsPath)\Microsoft.VisualBasic.targets</LanguageTargets>
      </PropertyGroup>
    </When>
  </Choose>
  <PropertyGroup>
    <AssemblySearchPaths>$(AssemblySearchPaths);{GAC}</AssemblySearchPaths>
    <ApplicationIcon />
  </PropertyGroup>

  <Target Name="PreCompileSelf" BeforeTargets="XamlTemporaryAssemblyGeneration" Condition="'$(MSBuildProjectExtension)' == '.csproj' and '$(SelfPreCompile)' != 'true'">
    <Message Text="Pre-compiling $(MSBuildProjectFile)..." Importance="high"/>
    <MSBuild Projects="$(MSBuildProjectFile)" Properties="Configuration=$(Configuration);Platform=$(Platform);SelfPreCompile=true" ContinueOnError="WarnAndContinue"/>
  </Target>
  <Target Name="CoreCompile" Condition="'$(MSBuildProjectExtension)' != '.csproj'">
    <!--Fake target - workaround for 2-phases build of projects with XAML files-->
    <Message Text="CoreCompile target called"/>
  </Target>
</Project>

Here is my sample
WorkflowConsoleApplication1.zip

The only way it work was build manually again.

@danielmeza
Copy link

@davidwengier and @davkean fix this will help to adopt the https://github.com/UiPath-Open/corewf project

@Nirmal4G
Copy link

Nirmal4G commented Apr 2, 2020

@DzonnyDZ @danielmeza

Some background on 2-Pass compilation of Xaml in WPF and WFF targets

The problem is similar to WPF's CreateTemporaryTargetAssembly which was fixed for supporting project files without xmlns tag a while back, around v4.7.x. But the same fix was not applied for WorkFlow Xaml targets which was in many ways similar in structure and code path to the WPF targets.

So, to solve this issue, you only need to add xmlns="http://schemas.microsoft.com/developer/msbuild/2003" back to your project file to generate the temporary project correctly.

So your project file becomes...
<Project Sdk="Microsoft.NET.Sdk" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <TargetFramework>net472</TargetFramework>
    <OutputType>Exe</OutputType>
  </PropertyGroup>
  <ItemGroup>
    <None Remove="Activity2.xaml" />
    <None Remove="Workflow1.xaml" />
  </ItemGroup>
  <ItemGroup>
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System" />
    <Reference Include="System.Activities" />
    <Reference Include="System.Core" />
    <Reference Include="System.Data" />
    <Reference Include="System.Runtime.Serialization" />
    <Reference Include="System.ServiceModel" />
    <Reference Include="System.ServiceModel.Activities" />
    <Reference Include="System.Xaml" />
    <Reference Include="System.Xml" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="WindowsBase" />
  </ItemGroup>
  <ItemGroup>
    <XamlAppDef Include="Activity2.xaml">
      <Generator>MSBuild:Compile</Generator>
    </XamlAppDef>
    <XamlAppDef Include="Workflow1.xaml">
      <Generator>MSBuild:Compile</Generator>
    </XamlAppDef>
  </ItemGroup>
  <Choose>
    <When Condition="'$(MSBuildProjectExtension)' != '.csproj' and '$(MSBuildProjectExtension)' != '.vbproj'">
      <PropertyGroup>
        <LanguageTargets Condition="Exists('$(MSBuildProjectDirectory)\$(AssemblyName).csproj')">$(MSBuildToolsPath)\Microsoft.CSharp.targets</LanguageTargets>
        <LanguageTargets Condition="Exists('$(MSBuildProjectDirectory)\$(AssemblyName).vbproj')">$(MSBuildToolsPath)\Microsoft.VisualBasic.targets</LanguageTargets>
      </PropertyGroup>
    </When>
  </Choose>
</Project>

and with my Extras SDK (which extends from claire's but her sdk don't have wff or wcf yet), you'd essentially have

<Project Sdk="MSBuild.NET.Extras.Sdk" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <PropertyGroup>
    <TargetFramework>net472</TargetFramework>
    <OutputType>Exe</OutputType>
    <EnableWffProjectSetup>true</EnableWffProjectSetup>
    <!--
        This is needed for Presentation tech used as a part of Activities lib.
        Only references are needed. Don't need to enable whole wpf support.
        You could also set `EnableWpfProjectSetup` to build both WPF and WFF in single exe!
     -->
    <EnableImplicitWpfReferences>true</EnableImplicitWpfReferences>
  </PropertyGroup>

</Project>

Note: I haven't updated my readme yet but the package (latest from myget) requires Visual Studio v16 (2019) but the old one on nuget works from v15.6 (2017 Update 6) onwards.

@davkean @davidwengier May I ask why was the fix not added to the WFF targets?

@danielmeza
Copy link

@Nirmal4G the project build and run as well! But, the designer can't load assembly from reference project in the solution. Its fail trying to load the .dll becasuse he way the assembly is searched. The problem ocurre whit reference project by another reference project. The workaround is to directly add the project as a reference.

@davidwengier
Copy link
Contributor

May I ask why was the fix not added to the WFF targets?

Those targets don't live in this repo so I'm afraid I couldn't say.

@davidwengier davidwengier removed their assignment Oct 18, 2020
@drewnoakes drewnoakes removed the Bug label Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature-XAML Features related to the XAML designer and display and manipulation of XAML files. Parity-Legacy-Feature Missing features from the legacy project system. Triage-Approved Reviewed and prioritized
Projects
None yet
Development

No branches or pull requests

6 participants