Thursday, April 22, 2010

MSBUILD 4.0, XmlPeek, XmlPoke, and MSB4036

I installed Visual Studio 2010. I was creating a new MSBUILD file and was delighted to find the new XmlPeek and XmlPoke tasks have been added to .NET Framework 4.0. However, when I tried the following:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="XmlPokeTest">
    <XmlPoke etc.../>
  </Target>
</Project>

... I get the dreaded task was not found message:

Microsoft (R) Build Engine Version 4.0.30319.1 Copyright (C) Microsoft Corporation 2007. All rights reserved. error MSB4036: The "XmlPoke" task was not found.

The error has a standard set of suggested solutions, including this one:

Check the following:
3.) The task is correctly declared within the project file,
or in the *.tasks files located in the
"C:\Windows\Microsoft.NET\Framework\v2.0.50727" directory.

This works:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <UsingTask TaskName="Microsoft.Build.Tasks.XmlPoke"
             AssemblyName="Microsoft.Build.Tasks.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
  <Target Name="XmlPokeTest">
    <XmlPoke etc.../>
  </Target>
</Project>

There is a Microsoft.Commmon.Tasks file in the C:\Windows\Microsoft.NET\Framework\v4.0.30319 folder that lists the new MSBuild 4.0 tasks, like XmlPeek and XmlPoke. But MSBuild 4.0 is apparently still using the Microsoft.Commmon.Tasks file in C:\Windows\Microsoft.NET\Framework\v2.0.50727.

Using the toolsversion switch also works, presumably causing MSBuild to reference the new 4.0 Microsoft.Common.Tasks file:

msbuild /toolsversion:4.0 XmlPokeTest.proj

For future reference, the 4.0 Microsoft.Common.Tasks file includes these entries that are not included in the the 2.0 version:

AssignProjectConfiguration
AssignTargetPath
CreateCSharpManifestResourceName
CreateVisualBasicManifestResourceName
FindAppConfigFile
FindInList
FormatUrl
FormatVersion
GenerateTrustInfo
GetReferenceAssemblyPaths
Move
RequiresFramework35SP1Assembly
ResolveManifestFiles
ResolveNonMSBuildProjectOutput
UpdateManifest
XmlPeek
XmlPoke
XslTransformation

Thursday, April 15, 2010

TemplateBinding and the Visual Studio 2010 WPF Designer

I upgraded to Visual Studio 2010. I was looking forward to the improved WPF designer. However, when I converted one of my projects I found that my WPF windows would not display properly. My windows that displayed properly in the VS2008 WPF designer were not displaying in the VS2010 WPF designer. Compiling and running worked fine in both. It was simply the designer complaining.

In VS2010, the designer complained about the window: "An error occurred while finding the resource dictionary."

In VS2010, the resource dictionary complained: "The type 'TemplateBinding' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built."

I found that my old resource dictionary had this default XML namespace for the XAML:
xmlns="http://schemas.microsoft.com/netfx/2007/xaml/presentation"

I found that a new resource dictionary created in VS2010 uses this default XML namespace:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

Replacing the default namespace in my old resource dictionary solved the problem.

Hope this helps you!