WPF应用程序在vs2k8中构建,但不在命令行w/msbuild上构建

jri*_*sta 5 msbuild wpf msbuild-task .net-3.5

我有一个相当小的解决方案,包括一个WPF Windows应用程序.从解决方案构建时,它构建完美.我最近将解决方案中包含的项目集成到一个使用MSBuild的现有的,更大的命令行构建中.但是,从命令行构建时,我会收到以下错误:

MainWindow.xaml.cs(12,4): error CS0103: The name 'InitializeComponent' does not exist in the current context
View\EngineMonitorView.xaml.cs(12,4): error CS0103: The name 'InitializeComponent' does not exist in the current context
View\HostingEngineView.xaml.cs(12,4): error CS0103: The name 'InitializeComponent' does not exist in the current context
View\MainView.xaml.cs(13,4): error CS0103: The name 'InitializeComponent' does not exist in the current context
View\MainView.xaml.cs(17,52): error CS0103: The name 'gView' does not exist in the current context
View\PerformanceCounterView.xaml.cs(22,4): error CS0103: The name 'InitializeComponent' does not exist in the current context
View\PerformanceCounterView.xaml.cs(117,22): error CS0103: The name 'cnvsCounterGrid' does not exist in the current context
View\PerformanceCounterView.xaml.cs(118,20): error CS0103: The name 'cnvsCounterGrid' does not exist in the current context
View\PerformanceCounterView.xaml.cs(127,4): error CS0103: The name 'cnvsCounterGrid' does not exist in the current context
View\PerformanceCounterView.xaml.cs(138,5): error CS0103: The name 'txtScale' does not exist in the current context
View\PerformanceCounterView.xaml.cs(179,5): error CS0103: The name 'txtLast' does not exist in the current context
View\PerformanceCounterView.xaml.cs(180,5): error CS0103: The name 'txtMin' does not exist in the current context
View\PerformanceCounterView.xaml.cs(181,5): error CS0103: The name 'txtMax' does not exist in the current context
View\PerformanceCounterView.xaml.cs(189,5): error CS0103: The name 'txtAverage' does not exist in the current context
View\PerformanceCounterView.xaml.cs(250,4): error CS0103: The name 'cnvsCounterGrid' does not exist in the current context
View\PerformanceCounterView.xaml.cs(251,4): error CS0103: The name 'cnvsCounterGrid' does not exist in the current context
View\PerformanceCounterView.xaml.cs(253,27): error CS0103: The name 'cnvsCounterGrid' does not exist in the current context
View\PerformanceCounterView.xaml.cs(255,27): error CS0103: The name 'cnvsCounterGrid' does not exist in the current context
View\PerformanceCounterView.xaml.cs(264,4): error CS0103: The name 'cnvsCounterGrid' does not exist in the current context
View\PerformanceCounterView.xaml.cs(269,4): error CS0103: The name 'cnvsCounterGrid' does not exist in the current context
View\PerformanceCounterView.xaml.cs(274,4): error CS0103: The name 'cnvsCounterGrid' does not exist in the current context
View\PerformanceCounterView.xaml.cs(279,4): error CS0103: The name 'cnvsCounterGrid' does not exist in the current context
View\PerformanceCounterView.xaml.cs(293,5): error CS0103: The name 'cnvsCounterGrid' does not exist in the current context
View\PerformanceCounterView.xaml.cs(303,5): error CS0103: The name 'cnvsCounterGrid' does not exist in the current context
View\PerformanceCounterView.xaml.cs(318,5): error CS0103: The name 'cnvsCounterGrid' does not exist in the current context
View\PerformanceCounterView.xaml.cs(325,5): error CS0103: The name 'cnvsCounterGrid' does not exist in the current context
View\PerformanceCounterView.xaml.cs(342,4): error CS0103: The name 'cnvsCounterGrid' does not exist in the current context
View\ServerMonitorView.xaml.cs(12,4): error CS0103: The name 'InitializeComponent' does not exist in the current context
View\ServerTreeView.xaml.cs(12,4): error CS0103: The name 'InitializeComponent' does not exist in the current context
View\ServiceDetailView.xaml.cs(12,4): error CS0103: The name 'InitializeComponent' does not exist in the current context
View\ServiceMonitorView.xaml.cs(12,4): error CS0103: The name 'InitializeComponent' does not exist in the current context
Run Code Online (Sandbox Code Playgroud)

我在我们的根MSBuild .proj文件中包含了.NET 3.5中的WinFX目标文件,因为它似乎没有包含在其他地方:

<Import Project="$(MSBuildBinPath)\Microsoft.WinFX.targets" />
Run Code Online (Sandbox Code Playgroud)

但这似乎并没有影响任何事情,我仍然遇到错误.据我所知,似乎将.xaml文件预编译为.cs文件,嵌入和连接资源等的自定义WPF构建任务没有运行,这就是为什么InitializeComponent和我的视图中定义的任何控件都是未找到.我不知道为什么,虽然......并且试图浏览与WPF和MSBuild相关的数以万计的搜索结果并没有让我到处都是.

更新:

将Microsoft.WinFX.targets添加到.csproj文件似乎可以正常工作.但是,这样做会导致项目无法在Visual Studio 2008中构建.不知何故,VS会为您包含这些目标......但我不确定如何.有谁知道VS如何构建WPF项目?是否存在隐藏某个导入适当目标的主构建文件?

And*_*ott 5

发送msbuild您的解决方案文件而不是.csproj文件有时可以帮助:

msbuild.exe yoursolution.sln
Run Code Online (Sandbox Code Playgroud)

此外,devenv.exe本身提供了一个命令行构建,它应该等同于in-IDE体验:

devenv.exe /build yoursolution.sln
Run Code Online (Sandbox Code Playgroud)

  • @Lavinski你最终可能需要重新考虑.例如,如果您希望构建服务器能够构建Web应用程序或MSTest单元测试项目,那么我知道安装必要构建工具的唯一方法是在构建服务器上安装VS. (2认同)