Created
July 26, 2012 08:02
-
-
Save sovanesyan/3180872 to your computer and use it in GitHub Desktop.
Nuget Package Add Import and Errors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Need to load MSBuild assembly if it's not loaded yet. | |
Add-Type -AssemblyName 'Microsoft.Build, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' | |
# Grab the loaded MSBuild project for the project | |
$msbuild = [Microsoft.Build.Evaluation.ProjectCollection]::GlobalProjectCollection.GetLoadedProjects($project.FullName) | Select-Object -First 1 | |
# Make the path to the targets file relative. | |
$projectUri = new-object Uri('file://' + $project.FullName) | |
$targetUri = new-object Uri('file://' + $targetsFile) | |
$relativePath = $projectUri.MakeRelativeUri($targetUri).ToString().Replace([System.IO.Path]::AltDirectorySeparatorChar, [System.IO.Path]::DirectorySeparatorChar) | |
$existsCondition = "Exists('" + $relativePath + "')" | |
#Add the enhancer item definition | |
# Add the import | |
$importElement = $msbuild.Xml.AddImport($relativePath) | |
$importElement.Condition = $existsCondition | |
#hook the error task | |
$beforeBuildTask = $msbuild.Xml.Targets | Where {$_.Name -eq "BeforeBuild"}| Select-Object -First 1 | |
if( $beforeBuildTask -eq $null) | |
{ | |
$beforeBuildTask = $msbuild.Xml.AddTarget("BeforeBuild") | |
} | |
$errorTask = $hookTarget.AddTask("Error") | |
$errorTask.SetParameter("Text", "SomeText") | |
# Save the project | |
$project.Save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment