| 1 |
param($installPath, $toolsPath, $package, $project) |
| 2 |
# This is the MSBuild targets file to add |
| 3 |
$targetsFile = [System.IO.Path]::Combine($toolsPath, $package.Id + '.targets') |
| 4 |
|
| 5 |
# Need to load MSBuild assembly if it's not loaded yet. |
| 6 |
Add-Type -AssemblyName 'Microsoft.Build, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' |
| 7 |
|
| 8 |
# Grab the loaded MSBuild project for the project |
| 9 |
$msbuild = [Microsoft.Build.Evaluation.ProjectCollection]::GlobalProjectCollection.GetLoadedProjects($project.FullName) | Select-Object -First 1 |
| 10 |
|
| 11 |
# Make the path to the targets file relative. |
| 12 |
$projectUri = new-object Uri('file://' + $project.FullName) |
| 13 |
$targetUri = new-object Uri('file://' + $targetsFile) |
| 14 |
$relativePath = $projectUri.MakeRelativeUri($targetUri).ToString().Replace([System.IO.Path]::AltDirectorySeparatorChar, [System.IO.Path]::DirectorySeparatorChar) |
| 15 |
|
| 16 |
# Add the import and save the project |
| 17 |
$msbuild.Xml.AddImport($relativePath) | out-null |
| 18 |
$project.Save() |