dotnet / project-system

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

Folder based projects and wpf #3574

Closed dgxhubbard closed 5 years ago

dgxhubbard commented 6 years ago

We are in the process of switching some of our code base to .net core. After seeing the new folder based projects we decided to convert our old projects, class libraries, by hand to the new project format. I am using this guide because I have not seen much for doing project conversions. So far the conversion is going well. However, we have several wpf class libraries, where views are made available to applications. When we left the project to hook up the xaml and code behind they were not linked together, so we are leaving the xaml and code behind files as they were in the older project and upgrading the other portions of the project. I am trying to get some guidance on if the is what I should do, or is there an xml format in the new project files I have not been able to find.

Pilchie commented 6 years ago

@dgxhubbard - we're just getting started in bringing up the WPF designer in the new project system. In the meantime, @onovotny might have pointers on how to get some of this working.

dgxhubbard commented 6 years ago

Thanks any help would be appreciated

clairernovotny commented 6 years ago

If you use my MSBuild.Sdk.Extras package, you can target WPF. Your dev box needs net472 on it since there are build-time fixes there, even if you target a lower version.

You can see it with NuGet Package Explorer. The designer works as well, but Blend does not.

dgxhubbard commented 6 years ago

@onovotny I am not sure I am doing this correctly. I have installed MsBuild.Sdk.Extras as a package for the project. For example I have in the project file compile and dependent on for Foo.xaml.cs and Page directive for Foo.xaml

<ItemGroup>
    <Compile Include="Controls\Foo.xaml.cs">
      <DependentUpon>Foo.xaml</DependentUpon>
    </Compile>
  </ItemGroup>

  <ItemGroup>
    <Page Include="Controls\Foo.xaml">
      <SubType>Designer</SubType>
      <Generator>MSBuild:Compile</Generator>
    </Page>
  </ItemGroup>

I load the sln with the project and build and I get Foo.xaml.cs as a duplicate compile item Is there something I am doing wrong?

clairernovotny commented 6 years ago

@dgxhubbard you don't need to include anything manually. The SDK Extras includes the XAML and the designer files for you by default.

dgxhubbard commented 6 years ago

@onovotny I have done this two ways.

  1. Not including the compile/dependency for code behind and xaml page directives in the project.

    Using this the xaml and code behind are NOT linked in project under solution explorer, and we get the compile error "Your project.json doesn't have a runtimes section. You should add '"runtimes": { "win": { } }' to your project.json and then re-run NuGet restore."

  2. Including the compile/dependency for code behind and xaml page directives in the project.

    Using this the xaml and code behind are linked in project under solution explorer, but we get the duplicate compile item.

clairernovotny commented 6 years ago

Do you have a repro somewhere?

Here's how I have it in NPE: https://github.com/NuGetPackageExplorer/NuGetPackageExplorer/blob/a33d4fe094bb92c6677d81ed519169d9f2d55172/PackageExplorer/NuGetPackageExplorer.csproj#L23

The designers work there and it compiles without error.

dgxhubbard commented 6 years ago

From looking at your project file I added this line:

<Import Project="$(MSBuildSDKExtrasTargets)" Condition="Exists('$(MSBuildSDKExtrasTargets)')" />

now things are compiling and linked

davkean commented 5 years ago

We're tracking these features via the Feature-XAML label.