Closed petroemil closed 4 years ago
Sunburst.NET.Sdk.WPF appears to be a partial fork of my MSBuild.Sdk.Extras SDK. It hasn't been updated in a year and the repo is marked as archived on GitHub: https://github.com/SunburstApps/MSBuildSdks
Can you try using MSBuild.Sdk.Extras/2.0.24
and see if that solves your problem?
Using MSBuild.Sdk.Extras/2.0.24
raises other problems.
error CS5001: Program does not contain a static 'Main' method suitable for an entry point
App.Run
, the XAML files are still not compiled properly and they keep complaining about missing InitializeComponent
For the Extras, have you added a property UseWpf
set to true
?
I have, but doesn't seem to make any difference.
I really don't want to waste anybody's time... is it supposed to work (with the SDK Extras) or should I just wait for the .NET Core 3.0 SDK to come out of Preview and then I can use this?
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
We have no official support for WPF outside of what's coming with .NET Core 3.0; there's non-trivial amount of bugs/work (such as real code generator support) that will only work in 16.1 onwards.
For the reason that project is broken in VS 2019, is because of:
System.IO.DirectoryNotFoundException: 'Could not find a part of the path 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\16.0\Bin\Microsoft.CSharp.targets'.'
That path in Dev16 is; C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.CSharp.targets'. The SDK needs to be fixed.
We shouldn't be letting you open this project due some critical missing components, trying to figure out why we do.
I've had success by creating a shared project and storing the XAML files along with their code behind in the shared project. Other code files can go in the regular (SDK-format) project folder.
We added support for WPF projects in 16.3, closing this out.
@davkean
We added support for WPF projects in 16.3, closing this out.
To clarify, do you mean support for .NET Core WPF projects? Or do you mean WPF .NET Framework projects using the SDK-style csproj?
We also added support for consuming WPF from a .NET Framework SDK-style project.
@davkean I got to ask how that's supposed to be working. We created .Net Standard projects which were initially not inteded to contain WPF. Yet we had to add WPF-related classes (UserControls for example) and thus changed the target framework to "net472". Currently I tried both "Microsoft.NET.Sdk" and "Microsoft.NET.Sdk.WindowsDesktop". Yet VisualStudio does show ".xaml" and ".xaml.cs" files separately, I cannot switch to code via F7 in designer and I have no templates available for WPF (not a drastic issue, yet annoying).
I simply can't find any resource on how to set up the project file so this is all working. Sadly there's lots of intransparancy and a lack of resources.
I am not yet permitted to upgrade to .Net Core 3 as we're having two open not yet finished projects and my team leader doesn't want to introduce any unnecessary issues/bugs right now.
Thank you for any help!
@Skyppid Generally, the following works for me:
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<TargetFrameworks>net472</TargetFrameworks>
<RootNamespace>MyProjectName</RootNamespace>
<AssemblyName>MyProjectName</AssemblyName>
<UseWPF>true</UseWPF>
</PropertyGroup>
</Project>
For me, Solution Explorer groups the code-behind files under the XAML files, and provides proper Intellisense when opening the XAML. I also get WPF templates for Add new item....
There still appears to be a bug when using XAML in a shared project in VS Community currently under investigation. If this applies to you, you could try one of the listed workarounds -- either
Thanks @zspitz I indeed overlooked the "UseWPF". But nonetheless (even after a restart) the Solution Explorer does not merge designer and code files together. Everything else works after a few hiccups.
EDIT: Tried removing all .xaml related entries in the project file, excluded them and re-added them (both, only .cs, only .xaml) and it just doesn't get it. It always shows them as seperate files. They're named the same of course.
@Skyppid
@zspitz I use the latest 2019 (16.6) version. If I do that, I cannot switch to code either.
EDIT: I found the culprit. The files were named .cs and not .xaml.cs for some reason (I used to copy them because the templates did not work - not sure why the .xaml. went missing.
Sorry for the inconvenience!
Visual Studio Version: 2019
Summary: Before the .NET Core 3.0 SDK (that is still not out of Preview at the time of raising this issue), there was a "hack" to make it possible to use SDK style project files with WPF projects.
With Visual Studio 2017 this worked perfectly well, but in Visual Studio 2019 these projects seems to be broken, displaying only XAML files in the Solution Explorer and not picked up by build either.
Steps to Reproduce:
Expected Behavior: Work just like it used to in VS2017
Actual Behavior: Broken - as explained above
User Impact: Can't work on these WPF projects in VS2019