dotnet / project-system

The .NET Project System for Visual Studio
MIT License
969 stars 387 forks source link

Windows Forms and WPF project support #2963

Closed jnm2 closed 4 years ago

jnm2 commented 6 years ago

I could not find another issue tracking Windows Forms and WPF support in its entirety. The main justification for the decision to unify everything under .csproj was build SDK compatibility and I'm still looking forward to the list of benefits across the board. There are crucial ways in which legacy csproj just doesn't interoperate with the modern SDK.

For one example out of many, we are sorely missing a Pack target. Right now I have to write this kind of code to generate my own nuspec which is a crude hack. I am now searching for the best way to parse and handle PrivateAssets="all" and other values:

IReadOnlyList<(string id, string version)> ReadNuspecDependencies(string legacyCsproj)
{
    using (var reader = XmlReader.Create(legacyCsproj))
    {
        reader.MoveToContent();
        var namespaceManager = new XmlNamespaceManager(new NameTable());
        namespaceManager.AddNamespace("m", "http://schemas.microsoft.com/developer/msbuild/2003");

        return (
            from element in XNode.ReadFrom(reader).XPathSelectElements("/m:ItemGroup/m:PackageReference", namespaceManager)
            select (element.Attribute("Include").Value, element.Attribute("Version").Value)
        ).ToList();
    }
}

In order to be able to pack properly, we'll need to be able to move the modern SDK. That means:

@davkean, you invited me in January to create and link back each of these items. Is that still a helpful thing to do?

Again, the legacy SDK combined with Windows Forms has already been less than friendly to us for years and years. But after tasting the new opportunities of the modern SDK in our libraries and console apps, it's becoming ever more frustrating to continue putting up with the discrepancy.

huoyaoyuan commented 6 years ago

What's the status of UWP? Could it be tracked together? Some components could be shared with WPF.

wjk commented 6 years ago

@jnm2 @huoyaoyuan WPF support actually already works in SDK-style csproj, designer and all! See the MSBuild.Sdk.Extras package. You can see the README for basic instructions on how to use it, but please note that those instructions are out-of-date. Instead, see the WPF sample instead.

I would recommend copy/pasting the entire contents of WpfApplication.csproj into your csproj, because the correct MSBuild invocation for WPF designer support is quite quirky. However, if you do this, you will need to change the OriginalProjectName property to contain the name of the csproj file, without its extension (do not use $(MSBuildProjectFileName) here, it won't work). If you don't keep this value up to date, the WPF designer won't "see" NuGet packages you've referenced.

I was actually the one who got the WPF support to work. 😄 Hope this helps!

jnm2 commented 6 years ago

Very interesting! I spend almost all my time in Windows Forms rather than WPF, but I'll look for a chance to try it out.

Pilchie commented 6 years ago

We're still working out a timeline for improved support of other project types. That's currently being superseded by performance and reliability work for our existing scenarios. Going to put this in our "Unknown" milestone until it becomes a focus.

MagicAndre1981 commented 5 years ago

@Pilchie

any update on this? When can we expect official support? VS16/2019?

davkean commented 5 years ago

@MagicAndre1981 As per the roadmap and feature list, 2019/16.0 will include WinForms/WPF support.

MagicAndre1981 commented 5 years ago

@Pilchie thanks for the links. I haven't noticed them before

davkean commented 4 years ago

Going to close this - WPF/WinForms support was adding in 16.3/16.4 timeframe. I've looked through all the listed items and we have addressed all them. Please file individual bugs for any new issues that you encounter.