project-system: XAML files are not supported
From @tannergooding on February 3, 2017 22:56
Attached is a simple repro solution. WpfCps.zip
Issue 1: XAML files are treated as None
, when they should be treated as Page
with Generator=MSBuild:Compile
and SubType=Designer
metadata.
Issue 2: Page
items are not visible in the Solution Explorer
Issue 3: xaml.cs files are not properly nested under the xaml file
Issue 4: Compilation fails with: 1>C:\windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.WinFx.targets(419,45): error MSB4057: The target "CoreCompile" does not exist in the project.
Copied from original issue: dotnet/sdk#810
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 14
- Comments: 54 (27 by maintainers)
@tannergooding We’ve been working on our WPF application for several years and are still creating new ones. We (can’t speak for others…) would prefer, by far, a breaking change than not having CPS support. A breaking change we can deal with. We notice it, we learn about it, we apply the changes and we move on. The split between CPS and old style projects has already created issues for us several times as we’ve also got .net core frontends. Using CPS everywhere would enable us to share more of our build chain and make our build chain/infrastructure simpler, too. Currently we have to duplicate quite some code and that creates continuous friction - much worse than a breaking change.
That said, however, we’d also be fine with CPS WPF support being an opt-in. Let’s say you could add a *.targets import to every WPF csproj or something like that.
Done https://github.com/aienabled/WpfNetStandardSample but it has a problem with VS IntelliSense for WPF generated code (from intermediate folder) as I’ve described in the readme there. I hope someone from the Project System team will take a look at that sample and figure out why VS IntelliSense doesn’t work properly. Meanwhile, I’m using it with ReSharper without any issues.
@sharwell I’ll give you the same advice too for ILSpy 😉 Iet’s keep our efforts/workarounds consolidated if we can.
@Latency I would strongly suggest you use my
MSBuild.Sdk.Extras
package instead of adding that code to your own project. I have the WPF workarounds/“stuff” in there based on @sharwell and others’ work. If there’s other issues/enhancements, I’m happy to take PR’s to fix.My objective with that package is to fill the box and make it clean/simple to use with SDK style projects until there’s direct support from Microsoft.
The MSBuild.Sdk.Extras supports this now with changes based on @sharwell’s work
@bdovaz at this point, I think what I have in my Extras is as good as it gets. Official word is that it’s not supported in VS 2017 and it’s on the roadmap for the next release: https://github.com/dotnet/project-system/blob/master/docs/repo/roadmap.md
If you don’t want to wait, as I don’t, then everything is on a best-effort “we’ll try to find workarounds” basis.
@aienabled there’s a bit more to it than that, unfortunately. You have to deal with the
tmp_proj
2-pass of WPF.Using MSBuild.Sdk…Extras, I have an example here:
https://github.com/NuGetPackageExplorer/NuGetPackageExplorer/blob/master/PackageExplorer/NuGetPackageExplorer.csproj
Note the workarounds currently needed at the top/bottom of the csproj.
I’ll get some updated docs on the project that show how.
Workaround in RepoToolset (included via Directory.Build.props):
Turns out the XAML build sets the
AssemblyName
property to the original value.@aienabled, i wasn’t indicating it should avoid .tmp_proj, I’m saying t should usee the original projects file extension when doing so. Meaning instead of .tmp_proj, it should use .tmp_proj.csproj or just .csproj.
For me it works good with VS2017 RC and the class library project (.NET Framework, not .NET Standard). I can include XAML files and everything is properly compiled, Intellisense works, etc. The only issue I have is when I use globbing - the dependent
.xaml.cs
files are not nested. Reported there https://github.com/Microsoft/VSProjectSystem/issues/169UPD. I also checked default class library project (the template with .NET Standard). After switching target to net461 it works but indeed it treats XAML as
None
… and manual setting it toPage
leads toThe target "CoreCompile" does not exist in the project
error.@onovotny I will be happy to give that a try… It looks solid!
To be clear, I am removing the entire
<ItemGroup>
section and the<LanguageTargets>
line also as shown in my snip-it with this?On initial compile… it appears to pass the pre-checks. Since, my project is broke down for reconstruction on a major build ATM, I have lots of debugging to do… and can not validate this!
What I can tell you is that something is missing from being able to compile the XAML files now after using your .nupkg.
I am getting missing references to override OnClosing() in a few of my XAML files and about 100 less errors than my version which seems suspicious. I am not sure what order the compiler is checking things here.
Q: I assume that I would need to resolve these OnClosing() issues before seeing the other 100 problems with the project that still remain to be debugged?
Q: What am I missing now and which of these rules I posted redundant in your package? (too busy to investigate)
I have had to revert to keeping the rules from my above listed example to finish debugging my project until I can get a more clarity on which rules I must keep in conjunction with your
Extensions
package.Q: Is the
Workaround
.nupkg of yours deprecated and been replaced with theExtensions
one now?Q: For Blend 2017, it appears it is not supporting the new build configuration formats. Any thoughts regarding that? Are we supposed to wait for a fix from Microsoft on this?
@bdovaz, a few months ago I’ve made this repository https://github.com/aienabled/WpfNewProjectSystemSample I’ve just updated it to support latest version of VS2017 and include my latest workarounds. Maybe it will be helpful to you.
❓ @bdovaz I notice you have
Generator="MSBuild:UpdateDesignTimeXaml"
. Is there a reason you aren’t usingGenerator="MSBuild:Compile"
?Here’s one project that I’ve been working on that uses XAML. I need to look back and see if IntelliSense is working properly.
https://github.com/Microsoft/perfview/blob/aa6bfb7d5dec6144979b3399c46818907e068885/src/PerfView/PerfView.csproj#L99
Anyone got this working? I’m able to compile it but I lost intellisense in VS 2017.
This is my csproj: