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

Jul 22, 2011 at 11:16 AM

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

param($installPath, $toolsPath, $package, $project)   
    $project.Object.References.Add("System.Web")

 

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 2: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 5:30 PM

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

Jul 22, 2011 at 7: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 7: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 23, 2011 at 12:01 AM

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

Jul 23, 2011 at 12:04 AM

No

Jul 23, 2011 at 12:04 AM

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

Jul 23, 2011 at 12:07 AM

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 23, 2011 at 12:13 AM

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.

Developer
Jul 23, 2011 at 12:57 AM

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

http://docs.nuget.org/docs/reference/nuspec-reference#Specifying_Framework_Assembly_References_(GAC)