Porównaj ceny domen i usług IT, sprzedawców z całego świata

Jak przenieść projekty WPF do nowego formatu VS2017


Migruję swoje projekty do nowego formatu Visual Studio 2017, który działa dobrze we wszystkich standardowych bibliotekach, dopiero teraz mam problemy z bibliotekami interfejsu użytkownika, w których używam Wpf/Xaml.
Nie mogę dowiedzieć się, jak to zrobić dla moich niestandardowych elementów sterujących. Wydaje się, że stara klauzula już nie obowiązuje.
Czy ktoś ma pomysł, jak to zrobić i czy to w ogóle możliwe.
Zaproszony:
Anonimowy użytkownik

Anonimowy użytkownik

Potwierdzenie od:


13 grudnia 2018 -

Zapowiedziano .NET Core 3 Preview 1
https://blogs.msdn.microsoft.c ... orks/

NET Core 3 będzie obsługiwać aplikacje WPF i WinForms. Możesz to wypróbować z pakietem Preview SDK:
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<UseWPF>true</UseWPF>
</PropertyGroup>
</Project>


Poprzednia odpowiedź

Możesz użyć poniższego szablonu, aby zastąpić stary plik .csproj. To rozwiązuje kilka problemów, które mieli inni ludzie.
  • Nie musisz dołączać pośrednich plików
    * .g.cs
    , jak niektórzy sugerują.
  • Nie wystąpi błąd
    Main not found
    .
  • Brak błędu
    Nie można uruchomić projektu. Właściwość „RunCommand” nie jest zdefiniowana.
    nie nastąpi.
  • Obejmuje już skonfigurowane ustawienia domyślne i zasoby.

Szablon:
<pre class="lang-xml prettyprint-override">
<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>
Anonimowy użytkownik

Anonimowy użytkownik

Potwierdzenie od:

Po kilku poszukiwaniach i próbach i błędach, udało mi się!
To jest ostateczny WPF csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<LanguageTargets>$(MSBuildExtensionsPath)\$(VisualStudioVersion)\Bin\Microsoft.CSharp.targets</LanguageTargets>
<TargetFrameworks>net451</TargetFrameworks>
<RootNamespace>MyWpfLibrary</RootNamespace>
<AssemblyName>MyWpfLibrary</AssemblyName>
</PropertyGroup> <ItemGroup>
<PackageReference Include="Rx-Xaml" Version="2.2.5"/>
<PackageReference Include="reactiveui-core" Version="7.2.0"/>
</ItemGroup> <ItemGroup>
<ProjectReference Include="MyOtherLibrary.csproj"/>
</ItemGroup> <ItemGroup>
<Reference Include="PresentationCore"/>
<Reference Include="PresentationFramework"/>
<Reference Include="ReachFramework"/>
<Reference Include="System.Net"/>
<Reference Include="System.Printing"/>
<Reference Include="System.Xaml"/>
</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"/> <Page Include="**\*.xaml" SubType="Designer" Generator="MSBuild:Compile"/>
<Compile Update="**\*.xaml.cs" SubType="Designer" DependentUpon="%(Filename)"/> <Resource Include="Fonts\*.otf"/>
<Resource Include="Images\*.png"/>
</ItemGroup> <Import Project="$(MSBuildSDKExtrasTargets)" Condition="Exists('$(MSBuildSDKExtrasTargets)')"/>
</Project>
Anonimowy użytkownik

Anonimowy użytkownik

Potwierdzenie od:

Powyższe rozwiązanie działa dla bibliotek dll Wpf, ale przyniosłem je z powrotem, ponieważ projektant Resharper i Visual Studio nie działają już po tej zmianie. Głównie dlatego, że nie mogli połączyć XAML i kodu wstecznego podczas programowania. Ale projekt kompiluje się i działa.
W przypadku pliku wykonywalnego wpf musisz wykonać następujące czynności:
<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>
Anonimowy użytkownik

Anonimowy użytkownik

Potwierdzenie od:

jest

Sunburst.NET.Sdk.WPF
https://github.com/SunburstApp ... k.WPF
więc może być używany jak .NET SDK. Oto pełny przykład aplikacji WPF, w której zostaną uwzględnione wszystkie pliki
.cs
i
.xaml

automatycznie

:
<Project Sdk="Sunburst.NET.Sdk.WPF/1.0.47">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net40</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../WpfMath/WpfMath.csproj"/>
</ItemGroup>
</Project>

Kiedy budujesz ten projekt za pomocą
msbuild
(szczególnie nie miałem szczęścia z
dotnet build
), automatycznie pobierze SDK z NuGet i skonfiguruje wszystko.
Anonimowy użytkownik

Anonimowy użytkownik

Potwierdzenie od:

Teraz, gdy został wydany .NET Core 3, powinieneś go używać, jeśli możesz.
Ale jeśli nie, to stwierdziłem, że mogę utworzyć oddzielny projekt współdzielony tylko dla elementów XAML i mogę odwołać się do tego projektu z projektu w stylu zestawu SDK. Wszystko jest budowane poprawnie.
Zwróć uwagę, że projektant XAML nie działa - nie ma funkcji Intellisense ani czerwonych zawijasów. Program Visual Studio otwiera pliki XAML przy użyciu edytora XML.
Anonimowy użytkownik

Anonimowy użytkownik

Potwierdzenie od:

Powyższe rozwiązania mogą nie działać z Xamarin.Platforms.WPF na VS2019
Oto projekt (oparty na wcześniejszych odpowiedziach) zaprojektowany dla platformy .net (nie dla głównej aplikacji .net), ale zdolny do obsługi standardowych zależności .net:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<RootNamespace>TestWPF</RootNamespace>
<AssemblyName>TestWPF</AssemblyName>
<TargetFramework>net461</TargetFramework>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugType>full</DebugType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugType>pdbonly</DebugType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.Platforms" Version="3.0.0"/>
<PackageReference Include="Xamarin.Forms" Version="4.2.0.848062"/>
<PackageReference Include="Xamarin.Forms.Platform.WPF" Version="4.2.0.848062"/>
</ItemGroup>
<ItemGroup>
<Reference Include="PresentationCore"/>
<Reference Include="PresentationFramework"/>
<Reference Include="WindowsBase"/>
<Reference Include="System.Xaml"/>
</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"/> <ApplicationDefinition Include="App.xaml" Generator="MSBuild:Compile"/>
<Page Include="**\*.xaml" Exclude="App.xaml" SubType="Designer" Generator="MSBuild:Compile"/>
<Compile Update="**\*.xaml.cs" SubType="Designer" DependentUpon="%(Filename)"/> <EmbeddedResource Remove="**\*.xaml"/> </ItemGroup>
<Import Project="$(MSBuildSDKExtrasTargets)" Condition="Exists('$(MSBuildSDKExtrasTargets)')"/>
</Project>

Aby odpowiedzieć na pytania, Zaloguj się lub Zarejestruj się