$project.Object.References.Add fails in install PS-script

Jul 22, 2011 at 10:16 AM

I have the following PS-script inside my "tools" folder:

param($installPath, $toolsPath, $package, $project)   


In PS console I can execute  (Get-Project).Object.References.Add("System.Web") and it works.

But during installing I get the following error:

PM> Install-Package XXX
Successfully installed 'XXX 1.2.3'.
'packages.config' already exists. Skipping...
Successfully added 'XXX 1.4.2' to MyProject.
Exception calling "Add" with "1" argument(s): "Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))"
At D:\MyProject\packages\XXX.1.4.2\tools\install.ps1:2 char:35
+     $project.Object.References.Add <<<< ("System.Web")
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ComMethodTargetInvocation

What's wrong?

Isn't $project in PS-script the same as get-project in console ?

Jul 22, 2011 at 1:19 PM

yes, it should be the same as get-project. Is it possible that you share your project in order for us to investigate?

Jul 22, 2011 at 4:30 PM

If not, can you run VS with the /log switch and share the log file?

Jul 22, 2011 at 6:43 PM

The error was caused the fact that I installed my package into ClientProfile-project. And that's because adding reference to System.Web failed.

Jul 22, 2011 at 6:44 PM

BTW, I've noticed that if there're no "lib" folder in .nupkg then install.ps1 isn't executed at all. I think it's a bug.

Jul 22, 2011 at 11:01 PM

What is the structure of your package? Does it contain any file in the 'contents' folder?

Jul 22, 2011 at 11:04 PM


Jul 22, 2011 at 11:04 PM

so it only contains install.ps1 in the tools folder?

Jul 22, 2011 at 11:07 PM

Well, actually my package does contain some stuff in lib/tools. but for testing of the issue I used a package with PS-script only and notice it isn;t executed.

Jul 22, 2011 at 11:13 PM

If your package doesn't have anything in 'contents' or 'lib' folder, it is treated as a solution-level package. What it means is that it is only copied into the 'packages' folder under your solution root. That's it. It doesn't get installed into your project. As a result, we don't execute the install.ps1.

To work around that, you can put some nominal file, e.g. readme.txt, under 'content's folder.

Jul 22, 2011 at 11:57 PM

Just catching up on this thread. You shouldn't even be using $project.Object.References.Add("System.Web");, Instead using the framework assemblies feature :