Project unavailable error while unloading project from Install.ps1

Topics: General
Jan 10, 2013 at 7:03 PM

In my Install.ps1 I’ve managed to add a post build event to my project file using the msbuild api:

param($installPath, $toolsPath, $package, $project)
#save the project file first - this commits the changes made by nuget before this  script runs.

Add-Type -AssemblyName 'Microsoft.Build, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
$buildProject = [Microsoft.Build.Evaluation.ProjectCollection]::GlobalProjectCollection.GetLoadedProjects($project.FullName) | Select-Object -First 1

$buildEventText = 'REM Some post build event'

$propertyGroup = $buildProject.Xml.AddPropertyGroup()


$project.Save() #persists the changes

Now, this doesn’t show up in VS until the project is unloaded and reloaded. I’ve found this somewhat arcane way of doing this:

$shortpath = $dte.Solution.Properties.Item("Name").Value + "\" + $project.Name

#following GUID = Constants.vsWindowKindSolutionExplorer
#magic 1 = vsUISelectionType.vsUISelectionTypeSelect

However, when I install my package using this Install.ps1 I get this warning and error in the package manager console (PM):

PM> Install-Package MyPackage

Successfully installed 'MyPackage 1.0.1'.

Successfully added 'MyPackage 1.0.1' to ClassLibrary13.

Project unavailable.

Project unavailable.

Project unavailable.

Directory '' is not empty. Skipping...

Install failed. Rolling back...


Install-Package : Project unavailable.

At line:1 char:16

+ Install-Package <<<< MyPackage

   + CategoryInfo         : NotSpecified: (:) [Install-Package], COMException

   + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand


Please help me get around this problem?


Jan 10, 2013 at 7:53 PM

Try calling $buildProject.Save() instead of unloading and reloading the project.