2017-05-23 63 views
5

Ja eksperymentuje z migracją projektu WPF, określona przy użyciu starego formatu csproj, do nowego formatu pod VS 2017WPF App Korzystanie z nowego formatu csproj

udało mi się uzyskać większość drogi do udanej kompilacji używając informacji znalezionych pod adresem How-to migrate Wpf projects to the new VS2017 format.

Ale utknąłem na uzyskanie obok tego błędu:

error CS5001: Program does not contain a static 'Main' method suitable for an entry point

Mój nowy styl plik csproj jest następujący:

<Project Sdk="Microsoft.NET.Sdk"> 

    <PropertyGroup> 
    <LanguageTargets>$(MSBuildExtensionsPath)\$(VisualStudioVersion)\Bin\Microsoft.CSharp.targets</LanguageTargets> 
    <OutputType>winexe</OutputType> 
    <TargetFramework>net47</TargetFramework> 
    <ApplicationIcon /> 
    <OutputTypeEx>winexe</OutputTypeEx> 
    <StartupObject /> 
    </PropertyGroup> 

    <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" /> 
    <Compile Update="Settings.Designer.cs" AutoGen="True" DependentUpon="Settings.settings" /> 
    <None Update="Settings.settings" LastGenOutput="Settings.Designer.cs" Generator="SettingsSingleFileGenerator" /> 

    <Page Include="**\*.xaml" SubType="Designer" Generator="MSBuild:Compile" /> 
    <Compile Update="**\*.xaml.cs" SubType="Designer" DependentUpon="%(Filename)" /> 

    <Resource Include="assets\*.*" /> 
    </ItemGroup> 

    <ItemGroup> 
    <PackageReference Include="Autofac" Version="4.6.0" /> 
    <PackageReference Include="Autofac.Extras.CommonServiceLocator" Version="4.0.0" /> 
    <PackageReference Include="Extended.Wpf.Toolkit" Version="3.0.0" /> 
    <PackageReference Include="Hardcodet.NotifyIcon.Wpf" Version="1.0.8" /> 
    <PackageReference Include="MaterialDesignColors" Version="1.1.3" /> 
    <PackageReference Include="MaterialDesignThemes" Version="2.3.0.823" /> 
    <PackageReference Include="MvvmLightLibs" Version="5.3.0" /> 
    <PackageReference Include="Serilog" Version="2.4.0" /> 
    <PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.0" /> 
    </ItemGroup> 

    <ItemGroup> 
    <ProjectReference Include="..\..\WPFUtilities\J4JUI\J4JUI.csproj" /> 
    </ItemGroup> 

    <ItemGroup> 
    <Reference Include="System.ComponentModel.DataAnnotations" /> 
    </ItemGroup> 

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

Jak skonfigurować plik csproj więc tym punkcie wejścia zostanie zbudowany?

Aktualizacja

podstawie końcówki o ApplicationDefinition udało mi się dostać do kompilacji projektu. Nie mogłem ustawić ApplicationDefinition w BuildAction - nie był to jeden z wyborów - ale musiał ręcznie edytować plik csproj, aby go uwzględnić. Oto działająca wersja:

<Project Sdk="Microsoft.NET.Sdk"> 

    <PropertyGroup> 
    <LanguageTargets>$(MSBuildExtensionsPath)\$(VisualStudioVersion)\Bin\Microsoft.CSharp.targets</LanguageTargets> 
    <OutputType>winexe</OutputType> 
    <TargetFramework>net47</TargetFramework> 
    <ApplicationIcon /> 
    <OutputTypeEx>winexe</OutputTypeEx> 
    <StartupObject /> 
    </PropertyGroup> 

    <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" /> 
    <Compile Update="Settings.Designer.cs" AutoGen="True" DependentUpon="Settings.settings" /> 
    <None Update="Settings.settings" LastGenOutput="Settings.Designer.cs" Generator="SettingsSingleFileGenerator" /> 

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

    <Resource Include="assets\*.*" /> 

    <ApplicationDefinition Include="App.xaml"> 
     <Generator>MsBuild:Compile</Generator> 
     <SubType>Designer</SubType> 
    </ApplicationDefinition> 

    </ItemGroup> 

    <ItemGroup> 
    <PackageReference Include="Autofac" Version="4.6.0" /> 
    <PackageReference Include="Autofac.Extras.CommonServiceLocator" Version="4.0.0" /> 
    <PackageReference Include="Extended.Wpf.Toolkit" Version="3.0.0" /> 
    <PackageReference Include="Hardcodet.NotifyIcon.Wpf" Version="1.0.8" /> 
    <PackageReference Include="MaterialDesignColors" Version="1.1.3" /> 
    <PackageReference Include="MaterialDesignThemes" Version="2.3.0.823" /> 
    <PackageReference Include="MvvmLightLibs" Version="5.3.0" /> 
    <PackageReference Include="Serilog" Version="2.4.0" /> 
    <PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.0" /> 
    </ItemGroup> 

    <ItemGroup> 
    <ProjectReference Include="..\..\WPFUtilities\J4JUI\J4JUI.csproj" /> 
    </ItemGroup> 

    <ItemGroup> 
    <Reference Include="System.ComponentModel.DataAnnotations" /> 
    </ItemGroup> 

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

Należy również uwzględnić filtr wykluczenia dyrektywy. Konieczne jest, aby program MSBuild próbował dwukrotnie skompilować plik App.xaml.cs.

+0

Jesteś świętym. – damageboy

Odpowiedz

4

Musisz ustawić działanie kompilacji App.xaml na ApplicationDefinition. Wynik jest następujący element w csproj pliku:

<ApplicationDefinition Include="App.xaml"> 
    <Generator>MSBuild:Compile</Generator> 
    <SubType>Designer</SubType> 
</ApplicationDefinition> 
+0

Thanx! Musiałem dowiedzieć się, gdzie umieścić ten plik XML w pliku csproj, ponieważ funkcja BuildAction nie oferowała opcji ApplicationDefinition. –

+0

Jesteś także świętym! – damageboy

Powiązane problemy