通过msbuild使用XAML生成WPF应用程序

通过msbuild使用XAML生成WPF应用程序

问题描述:

我正在尝试通过自定义脚本(如下)使用msbuild构建一个简单的WPF应用程序.该项目可以通过Visual Studio生成并执行良好,但是,如果我使用msbuild脚本,则可以成功生成并生成可执行文件,但是在启动时立即崩溃(出现"WPFApplication已停止工作"错误消息).

I am attempting to build a simple WPF Application using msbuild via a custom script (below). The project builds and executes fine through Visual Studio, however if I use the msbuild script it builds successfully, and generates the executable, but crashes immediately on startup (with a "WPFApplication has stopped working" error message).

任何人以前都经历过此事,或者对尝试的事情有任何建议吗?

Has anyone experienced this before, or have any suggestions for things to try?

谢谢!

构建脚本

Build Script

    <PropertyGroup>
        <AssemblyName>WPFApplication</AssemblyName>
        <OutputType>winexe</OutputType>
    </PropertyGroup>

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

    <ItemGroup>
         <ApplicationDefinition Include="WpfBuild\WpfBuild\App.xaml" />
         <Compile Include="WpfBuild\WpfBuild\App.xaml.cs" />
         <Page Include="WpfBuild\WpfBuild\Window1.xaml" />
         <Compile Include="WpfBuild\WpfBuild\Window1.xaml.cs" />
     </ItemGroup>

     <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
     <Import Project="$(MSBuildBinPath)\Microsoft.WinFX.targets" />

</Project>

编辑csproj文件,并在其末尾靠近该行,并在其中包含"Microsoft.CSharp.targets"的行附近放置一个行:

Edit the csproj file and put a line similar to this near the end, near to the line with "Microsoft.CSharp.targets" in it:

<Import Project="$(MSBuildBinPath)\Microsoft.WinFX.targets" />

请参见 http://msdn.microsoft. com/en-us/library/aa970678%28VS.85%29.aspx

我目前正在寻找类似问题的答案.我找到了另一个SO链接 wpf-app -在vs2k8中构建,但不在命令行上使用w-msbuild

I'm currently looking for answers to something similar. I found another SO link wpf-app-builds-in-vs2k8-but-not-on-command-line-w-msbuild