RunCommand property not defined on WPF app migrate

2019-07-07 17:41发布

I am trying to migrate a WPF app built under the old csproj format to the new csproj format defined for VS2017.

I've been able to get the app to compile, but I when I try to launch it in the debugger under VS2017 I get the following error message:

Unable to run your project. The "RunCommand" property is not defined.

Interestingly, if I double-click the exe within File Explorer it launches just fine.

FYI, the project was initially a console app, which I then modified to be a WPF app. Here's the csproj file:

<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>

Where is the RunCommand property set, and how do I set it?

Update

Playing around with the project settings, I configured the debug options to launch the executable created by the project (the default is to "run" the project).

This lets me launch the app in the debugger within VS 2017...and makes me think this might be a bug in VS 2017, with the RunCommand property not being defined by the build environment the way it should be.

2条回答
Ridiculous、
2楼-- · 2019-07-07 17:54

For the 1.0.0 and 1.1.0 SDK, the Microsoft.NET.Sdk.targets file tries to set the RunCommand property when Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework' and '$(OutputType)' == 'Exe'". But since the project specifies <OutputType>winexe</OutputType> (which it needs to), the condition is not satisfied (and of course none of the others are either).

This seems to have been fixed in the upcoming 2.0.0 SDK (source, you'll have to explore the other files to find the _IsExecutable property), which should be shipped in the next VS2017 update.

In the meantime I opted to set the property manually in my .csproj: <RunCommand>bin\Debug\net47\MyApp.exe</RunCommand> (I could've spent more time to use more SDK-defined properties, but I'd have to schedule it after the SDK targets are imported, which I've left out for simplicity)

查看更多
甜甜的少女心
3楼-- · 2019-07-07 18:00

What kind of "migrate" are we talking here? There is no in-built migration tool, and it's way more than the previous "VS 2012 to VS2013" type upgrade, it's a fundamentally different format all together.

I know some people have tried (unsuccessfully) to manually update the .csproj XML, it usually ends in frustration and getting no where with it.

Honestly I would 100% recommend making brand new projects and manually copying your files in. Will take a while, but at least you'd be totally sure it was actually going to work, and you don't spend hours trying banging your head on the wall with the barely documented new XML format.

Of course a better option would be something built in to do it for you.

查看更多
登录 后发表回答