Skip to content

XAML intellisense file generation doesn't work in CPS projects #2488

Closed
dotnet/wpf
#1895

Description

@srivatsn

Add a XAML file to a CPS-based project.

Expected: file.g.i.cs should be generated in the obj directory during a design-time build so that intellisense knows about the types defined the XAML.

Actual: It's not generated and there are squiggles about missing definition for InitializeComponent etc.

Cause:
The old project system used to run the Compile target in a single msbuild instance and other targets to get outputgroups in a different instance. CPS batches them all and runs all targets in a single msbuild instance.

The generation of the .g.i.cs is done by a target called DesignTimeMarkupCompilation and that wants to run only during a DT build - to do that it only runs if $(BuildingProject) == 'true'`. Normally BuildingProject is false. However there's a target to get the PDB output group that sets it to true. Since it's the same msbuild instance that runs both targets, DesignTimeMarkupCompilation is being skipped.

Not sure what the right fix is here - the DesignTimeMarkupCompilation can check the $(DesignTimeBuild) property instead of BuildingInProject. Or maybe CPS needs to batch the targets into multiple batches.

A workaround to get this working is to add something like this to the project or to some import:

  <Target Name="WorkaroundForXAMLIntellisenseBuildIssue" AfterTargets="_CheckCompileDesignTimePrerequisite">
    <PropertyGroup>
       <BuildingProject>false</BuildingProject>
    </PropertyGroup>
  </Target>

This explicitly sets BuildingProject to false just before we run the CompileDesignTime target.

Activity

  1. srivatsn commented on Jun 22, 2017

    @srivatsn
    ContributorAuthor

    @tmat - can you please put in this workaround in the repo toolset when you move project system repo to repo toolset? Since we have a few XAML files, today if we have full solution analysis on, then there will be errors in the error list about missing InitializeComponent etc.

    Also @jaredpar - you'll need this as well for your branch that's moving roslyn to cps to avoid errors with full solution analysis on.

  2. jaredpar commented on Jun 22, 2017

    @jaredpar
    Member

    @srivatsn thanks for the heads up.

  3. tmat commented on Jun 23, 2017

    @tmat
    Member

    @srivatsn Sure.

  4. tmat commented on Jun 23, 2017

    @tmat
    Member

    I tried to add it but it broke the build. Xaml code behind is not generated at all to the obj dir during regular build

  5. srivatsn commented on Jun 23, 2017

    @srivatsn
    ContributorAuthor

    I added this to the project-system repo's targets files and I don't see any build breaks and it works fine in the IDE for me. We can take a look tomorrow.

  6. jaredpar commented on Jun 23, 2017

    @jaredpar
    Member

    The Roslyn build succeeded with this change as well.

  7. added this to the 15.5 milestone on Jul 11, 2017
  8. added a commit that references this issue on Sep 5, 2017
  9. 19 remaining items

  10. davidwengier commented on Jul 22, 2019

    @davidwengier
    Member

    Design time builds in Roslyn.sln no longer have anything that sets BuildingProject to true. I don't think this workaround is necessary any more, and I don't think this problem exists any more.

    If I'm mistaken, feel free to re-open.

  11. davkean commented on Jul 22, 2019

    @davkean
    Member

    @davidwengier BuildingProject is set to true when output groups are merged with design-time build, as called out in the linked msbuild bug above: dotnet/msbuild#2417.

  12. davidwengier commented on Jul 22, 2019

    @davidwengier
    Member

    Under what circumstances does that happen though? The list of targets in the top comment on that issue is not the list of targets that I'm seeing during a design time build. If this is dependant on project configuration, any hints you can give me to reproduce the issue would be greatly appreciated. This issue only mentions full solution analysis which I have turned on.

  13. davkean commented on Jul 22, 2019

    @davkean
    Member

    Two ways to approach this, go and figure out a feature that uses Output Groups and have it triggered in such a way that its gets combined with the first design-time build, or hack it up so that a target we do call during the build, depends on an output group target. The latter is probably easier to trigger and reproduce.

  14. modified the milestones: 16.3, 16.4 on Aug 28, 2019
  15. self-assigned this
    on Sep 18, 2019
  16. davidwengier commented on Sep 18, 2019

    @davidwengier
    Member

    The WPF targets have been updated.

  17. davkean commented on Sep 18, 2019

    @davkean
    Member

    Can we file a bug for .NET Framework projects?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Feature-XAMLParity-Legacy-FeatureTrackingTriage-Approved

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions