David Tchepak
David Tchepak

Reputation: 10464

Getting "Reference Assemblies" path in MSBuild

I'm updating a build to be compatible with .NET 4.5, and one of the changes I need to make is updating how I call ilmerge.

From the link above, this basically means changing:

/targetplatform:"v4,C:\windows\Microsoft.NET\Framework\v4.0.30319"

to:

/targetplatform:"v4,C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0"

In my MSBuild AfterBuild target I was generating the former using $(MSBuildToolsPath), like this:

/targetplatform:v4,$(MSBuildToolsPath)

What's the best way to translate this into the required /targetplatform:"v4,C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0" path so that it works on x64, x86 or any unusual places it can wind up installed?

Upvotes: 4

Views: 5397

Answers (2)

SoftwareCarpenter
SoftwareCarpenter

Reputation: 3923

Add the GetReferenceAssemblyPaths task within your target. Have it save the output to a item name or property and replace the $(msbuildtoolsPath) with this new property. You can also add a condition check to determine what you need to pass to ILMerge.

<GetReferenceAssemblyPaths BypassFrameworkInstallChecks="False" TargetFrameworkMoniker=".NETFramework,Version=v4.0">
    <Output TaskParameter="FullFrameworkReferenceAssemblyPaths" PropertyName="path" />
</GetReferenceAssemblyPaths>

Upvotes: 5

daughey
daughey

Reputation: 749

If you can find a registry key that contains the information (or important elements of the information you need) then I'd use the $(Registry:<key name>[@<value name>]) syntax to obtain it.

http://blogs.msdn.com/b/msbuild/archive/2007/05/04/new-registry-syntax-in-msbuild-v3-5.aspx

Upvotes: 0

Related Questions