未在 WPF 应用程序上定义的 RunCommand 属性已迁移到新的 csproj 格式 [英] RunCommand property not defined on WPF app migrated to new csproj format

查看:19
本文介绍了未在 WPF 应用程序上定义的 RunCommand 属性已迁移到新的 csproj 格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将在旧 csproj 格式下构建的 WPF 应用程序迁移到为 VS2017 定义的新 csproj 格式.

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

我已经能够编译应用程序,但是当我尝试在 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:

无法运行您的项目.未定义RunCommand"属性.

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

有趣的是,如果我在文件资源管理器中双击该 exe,它就可以正常启动.

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

仅供参考,该项目最初是一个控制台应用程序,然后我将其修改为一个 WPF 应用程序.这是 csproj 文件:

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>

RunCommand 属性在哪里设置,我该如何设置?

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

更新

玩弄项目设置,我配置了调试选项以启动项目创建的可执行文件(默认是运行"项目).

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

这让我可以在 VS 2017 中的调试器中启动该应用程序......并让我认为这可能是 VS 2017 中的一个错误,RunCommand 属性没有按照它应该的方式由构建环境定义.

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.

推荐答案

对于 1.0.0 和 1.1.0 SDK,Microsoft.NET.Sdk.targets 文件尝试设置Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework' 和 '$(OutputType)' == 'Exe'" 时的 RunCommand 属性.但由于项目指定了 winexe(它需要),条件不满足(当然其他条件都不满足).

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

这似乎已在即将发布的 2.0.0 SDK 中得到修复(source,您必须探索其他文件才能找到 _IsExecutable 属性),应该会在下一个 VS2017 更新中发布.

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.

与此同时,我选择在我的 .csproj 中手动设置属性:bin\Debug\net47\MyApp.exe(我本可以花更多时间使用更多 SDK 定义的属性,但我必须在导入 SDK 目标后安排它,为了简单起见,我省略了)

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)

这篇关于未在 WPF 应用程序上定义的 RunCommand 属性已迁移到新的 csproj 格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆