Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How-to migrate Wpf projects to the new VS2017 format

I'm migrating my projects to the new visual studio 2017 format which is working nicely for all standard libraries only now I run into problems with my UI libraries where I use Wpf / Xaml.

I cannot figure out howto do this for my user controls. The old item doesn't seem to be valid anymore.

Anybody has an idea howto do this or if it's even possible.

like image 480
Niek Jannink Avatar asked Apr 29 '17 08:04

Niek Jannink


People also ask

Can I migrate project types in Visual Studio 2017?

This present article provides details only for project types that Visual Studio 2017 can migrate. The article excludes project types that are no longer supported in Visual Studio 2017 and cannot therefore be migrated.

How to upgrade a Visual Studio project to a newer version?

Visual Studio offers to upgrade the project to the current schema. If you choose No, the project doesn't get upgraded. For projects created in Visual Studio 2010 and later, you can still use the project in the newer version of Visual Studio. Just set your project properties to continue to target the older toolset.

How to migrate from wdproj to Visual Studio 2019?

Because there is no equivalent in Visual Studio 2019, there is no automatic migration path for such projects. Instead, open the wdproj file in a text editor and copy-paste any customizations into to the pubxml (publish profile) file, as described on StackOverflow. Windows Communication Foundation, Windows Workflow Foundation

Will this change affect the modeling project in Visual Studio 2017?

This change does not affect the modeling project, but it does require changes to the code projects being validated. Visual Studio 2017 can automatically make the necessary changes to the code projects (more information). MSI Setup (vdproj) See InstallShield Projects.


2 Answers

December 13th 2018 - .NET Core 3 Preview 1 was announced

.NET Core 3 will support WPF and WinForms applications. You may try it with Preview version of SDK:

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <UseWPF>true</UseWPF>
  </PropertyGroup>
</Project>

Previous answer

You can use template below to replace old .csproj with. It resolves couple of issues other people templates had.

  1. You don't have to include intermediary *.g.cs files like some suggested to do.
  2. No Main not found error will occur.
  3. No Unable to run your project. The "RunCommand" property is not defined. error will occur.
  4. Includes already configured default Settings and Resources.

Template:

<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
  <PropertyGroup>
    <LanguageTargets>$(MSBuildExtensionsPath)\$(VisualStudioVersion)\Bin\Microsoft.CSharp.targets</LanguageTargets>
    <TargetFramework>net47</TargetFramework>
    <OutputType>WinExe</OutputType>
    <StartupObject />
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <DebugType>full</DebugType>
    <DebugSymbols>true</DebugSymbols>
  </PropertyGroup>

  <ItemGroup>
    <!-- App.xaml -->
    <ApplicationDefinition Include="App.xaml">
      <SubType>Designer</SubType>
      <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
    </ApplicationDefinition>

    <!-- XAML elements -->
    <Page Include="**\*.xaml" Exclude="App.xaml">
      <SubType>Designer</SubType>
      <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
    </Page>
    <Compile Update="**\*.xaml.cs" SubType="Code" DependentUpon="%(Filename)" />

    <!-- Resources -->
    <EmbeddedResource Update="Properties\Resources.resx" Generator="ResXFileCodeGenerator" LastGenOutput="Resources.Designer.cs" />
    <Compile Update="Properties\Resources.Designer.cs" AutoGen="True" DependentUpon="Resources.resx" DesignTime="True" />

    <!-- Settings -->
    <None Update="Properties\Settings.settings" Generator="SettingsSingleFileGenerator" LastGenOutput="Settings.Designer.cs" />
    <Compile Update="Properties\Settings.Designer.cs" AutoGen="True" DependentUpon="Settings.settings" />

  </ItemGroup>

  <ItemGroup>
    <Reference Include="PresentationCore" />
    <Reference Include="PresentationFramework" />
    <Reference Include="System.Xaml" />
    <Reference Include="WindowsBase" />
  </ItemGroup>
</Project>
like image 189
stil Avatar answered Oct 20 '22 07:10

stil


The above solution works for Wpf dll's, but I reverted it because Resharper and the Visual Studio designer where not functional anymore after this change. Mainly because they couldn't pair the xaml and the code-behind at design time. But the project compiles and works.

For a wpf executable you need to do the following:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <LanguageTargets>$(MSBuildExtensionsPath)\$(VisualStudioVersion)\Bin\Microsoft.CSharp.targets</LanguageTargets>
    <TargetFramework>net451</TargetFramework>
    <OutputType>WinExe</OutputType>
    <RootNamespace>MyNamespace</RootNamespace>
    <AssemblyName>MyExe</AssemblyName>
    <ApplicationIcon>MyExe.ico</ApplicationIcon>
    <ApplicationManifest>app.manifest</ApplicationManifest>
    <StartupObject>MyNamespace.App</StartupObject>
  </PropertyGroup>

  <ItemGroup>
    <Reference Include="PresentationCore" />
    <Reference Include="PresentationFramework" />
    <Reference Include="System.Xaml" />
    <Reference Include="WindowsBase" />
  </ItemGroup>

  <ItemGroup>
    <EmbeddedResource Update="Properties\Resources.resx" Generator="ResXFileCodeGenerator" LastGenOutput="Resources.Designer.cs" />
    <Compile Update="Properties\Resources.Designer.cs" DesignTime="True" AutoGen="True" DependentUpon="Resources.resx" />

    <None Update="Properties\Settings.settings" Generator="SettingsSingleFileGenerator" LastGenOutput="Settings.Designer.cs" />
    <Compile Update="Properties\Settings.Designer.cs" DesignTime="True" AutoGen="True" DependentUpon="Settings.settings" />

    <Page Include="MainWindow.xaml" SubType="Designer" Generator="MSBuild:Compile" />
    <Compile Update="MainWindow.xaml.cs" DependentUpon="MainWindow.xaml" />
    <Resource Include="Images\*.png" />

    <ApplicationDefinition Include="App.xaml" SubType="Designer" Generator="XamlIntelliSenseFileGenerator" />
    <Compile Update="App.xaml.cs" DependentUpon="App.xaml" />
  </ItemGroup>

  <Import Project="$(MSBuildSDKExtrasTargets)" Condition="Exists('$(MSBuildSDKExtrasTargets)')" />
</Project>
like image 12
Niek Jannink Avatar answered Oct 20 '22 06:10

Niek Jannink