【发布时间】:2009-11-04 00:29:11
【问题描述】:
我有一个相当小的解决方案,其中包括一个 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
我将 .NET 3.5 中的 WinFX 目标文件包含在我们的根 MSBuild .proj 文件中,因为它似乎没有包含在其他任何地方:
<Import Project="$(MSBuildBinPath)\Microsoft.WinFX.targets" />
不过,这似乎并没有影响任何事情,我仍然遇到错误。据我所知,将 .xaml 文件预编译为 .cs 文件、嵌入和连接资源等的自定义 WPF 构建任务似乎没有运行,这就是 InitializeComponent 和我视图中定义的任何控件的原因未找到。我不知道为什么,但是...尝试浏览与 WPF 和 MSBuild 相关的无数搜索结果并没有让我有任何收获。
更新:
将 Microsoft.WinFX.targets 添加到 .csproj 文件似乎可行。但是,这样做会导致项目无法在 Visual Studio 2008 中构建。不知何故,VS 为您包含了这些目标……但我不确定如何。有谁知道更多关于 VS 如何构建 WPF 项目的信息?是否有一个隐藏在某个地方的主构建文件可以导入适当的目标?
【问题讨论】:
-
我很乐意在这方面为您提供更多帮助,但我确实需要查看您的构建文件才能提供帮助。如果您无法共享我理解的实际构建文件,请尝试使用一个简单的新项目进行复制。
-
我很想分享我的构建文件,但是有将近十几个不同的文件导入到一个庞大的构建中。它是一个可怕的斑点,甚至不应该存在,但我工作的地方变化很慢。
-
你不能复制两个文件?一个代表您的“主要”构建文件,另一个包括项目的 .[cs|vb]proj?
-
我们的构建是一头荒谬的野兽。它涉及数十个文件,包括 .tasks、.targets、.proj 和 .components 文件。它不仅执行构建,还执行网站创建、GACing、部署等。尝试分解和创建模拟场景是一个长达数周的项目。我的问题主要是关于为什么,即使我已经导入了 Microsoft.WinFX.targets 文件,但实际上并没有调用 WPF 任务......我是否将 .targets 文件导入了错误的位置?有什么特别的担忧吗?是否还有其他需要包含的 .targets 文件?等等
标签: wpf .net-3.5 msbuild msbuild-task