Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF app builds in vs2k8, but not on command line w/ msbuild

I have a fairly small solution that includes a WPF windows application. It builds perfectly fine when built from the solution. I recently integrated the projects contained within the solution into an existing, much larger command line build that uses MSBuild. When built from the command line, however, I get the following errors:

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

I included the WinFX targets file from .NET 3.5 in our root MSBuild .proj file, as it did not appear to be included anywhere else:

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

That did not seem to affect anything, though, and I am still encountering the errors. As far as I can tell, it appears that the custom WPF build tasks that precompile the .xaml files into .cs files, embeds and wires up resources, etc. are not running, which is why InitializeComponent and any controls defined in my views are not found. I am at a loss as to why, though...and trying to wade through the zillions of search results related to WPF and MSBuild is not getting me anywhere.

UPDATE:

Adding the Microsoft.WinFX.targets to the .csproj file seems like it would work. However, doing so causes the project to fail to build within Visual Studio 2008. Somehow, VS is including those targets for you...but I am unsure how. Does anyone know more about how VS builds WPF projects? Is there a master build file hiding somewhere that imports the appropriate targets?

like image 231
jrista Avatar asked Nov 04 '09 00:11

jrista


People also ask

How do I create a project using MSBuild command line?

To build a specific target of a specific project in a solution. At the command line, type MSBuild.exe <SolutionName>. sln , where <SolutionName> corresponds to the file name of the solution that contains the target that you want to execute.

For which platforms can WPF applications be compiled?

WPF runtime libraries are included with all versions of Microsoft Windows since Windows Vista and Windows Server 2008.


2 Answers

Send msbuild your solution file instead of your .csproj file can sometimes help:

msbuild.exe yoursolution.sln

Also, devenv.exe itself offers a command-line build that's supposed to be equivalent to the in-IDE experience:

devenv.exe /build yoursolution.sln
like image 103
Andrew Arnott Avatar answered Oct 02 '22 12:10

Andrew Arnott


Check out this section of the MSDN SDK called Building WPF Applications and make sure you're doing everything you need.

like image 25
Drew Marsh Avatar answered Oct 02 '22 12:10

Drew Marsh