There’s been an annoying dialog box popping up each time I open my .NET project, getting rid of it proved a bit of a riddle but an interesting road of discovery which might solve a similar set of issues.

Security warning in the project

You can obviously select one of the settings and as Visual Studio to remember your decision, but I’m normally quite paranoid about such things and like to make the informed decision each time (for instance, would you blindly accept any sample code you downloaded from the internet?). So on clicking More Details, Visual Studio tells me that I’ve got an untrusted targets reference in my project file.

warning that there are untrusted targets

Now, in my case it’s moaning about a Microsoft.Expression.Blend.Silverlight.targets but it could be any other target file, particularly if you’ve added your own custom msbuild actions.

In my case, we’ve enabled font embedding into our Silverlight 3 application by ticking the checkbox in Expression Blend 3 (as shown below). This means that any non-standard web font that we use in the application will be available and therefore keeping the UI design as originally intended.

select font embedding in Expression Blend 3

However, this functionality is not built-in on a standard Silverlight project and actually requires an extra build step to embed the font file when the project is compiled and the XAP file constructed. Not-standard? That’s right, it’s an Expression Blend feature that either requires you to have Expression Blend 3 installed or the Expression Blend SDK (the latter is recommended if trying to compile the project on a build server).

Download the Expression Blend 3 SDK from here if you need it:
http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=f1ae9a30-4928-411d-970b-e682ab179e17

Since the prompted resolution is a registry setting in the Visual Studio tree, I guess that neither Expression Blend 3 or the Expression Blend SDK have the responsibility of adding this registry key, hence the warning. Thinking that it would be simple to follow the instructions on the screen, I did a search of the registry hive at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\MSBuild\SafeImports and found nothing… not even the registry node…

default 32bit registry node for target imports

Mass panic. Not only do I not have the node, but I have not got a clue as to what the format of any key or string value is meant to be*. The dialog’s instructions are not completely clear. That’s when I realised that I’m on 64bit Windows, in which parts of the registry are replicated/accessed in via a special node. Thus I should have been looking at HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\9.0\MSBuild\SafeImports  instead – where, I found plenty of other examples.

default 64bit registry node for target imports

So, now we know where the node it meant to exist, the format is to add a new string value to the appropriate node where:

Value Name: Microsoft.Expression.Blend.Silverlight.targets
Value Data: C:\Program Files (x86)\MSBuild\Microsoft\Expression\Blend\3.0\Silverlight\Microsoft.Expression.Blend.Silverlight.targets
(note, this is the valid path to the targets file).

After the registry value has been added, restart all instances of Visual Studio so that the solutions/projects pick up the change.


Tidied up, you could put this into a registry file like in the examples below:

For 32bit Windows

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE \Microsoft\VisualStudio\9.0\MSBuild\SafeImports]
"Microsoft.Expression.Blend.Silverlight.targets"="C:\\Program Files
\\MSBuild\\Microsoft\\Expression\\Blend\\3.0\\Silverlight\\Microsoft.Expression.Blend.Silverlight.targets"

For 64bit Windows

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\9.0\MSBuild\SafeImports]
"Microsoft.Expression.Blend.Silverlight.targets"="C:\\Program Files (x86)
\\MSBuild\\Microsoft\\Expression\\Blend\\3.0\\Silverlight\\Microsoft.Expression.Blend.Silverlight.targets"

 

* thanks to Merrick, who’s been sharing my ‘mass panic’ and helped by locating this 64bit registry feature!

 

This is a cross post from my EMC blog, mainly for backup duplicity and to aggregate some of my past postings. My EMC blog used to be under the Conchango brand but was acquired by EMC so I’ve also retrospectively refreshed some of the old links and maybe a tweak a bit of content too.
permalink to the original post here