0
votes

I am trying to install this package using the package manager console.

https://www.nuget.org/packages/WebDriver.IEDriverServer.win32/

Package Manager: 2.8.50313.31

install.ps1

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

$file = Join-Path (Join-Path $toolsPath '..\content') 'IEDriverServer.exe' | Get-ChildItem

$project.ProjectItems.Item($file.Name).Delete()

$project.ProjectItems.AddFromFile($file.FullName);
$pi = $project.ProjectItems.Item($file.Name);  # this line fails
$pi.Properties.Item("BuildAction").Value = [int]2;
$pi.Properties.Item("CopyToOutputDirectory").Value = [int]2;

Error:

Exception calling "Item" with "1" argument(s): "The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))"
At C:\dev\Projects\AttachmentUnitTests\packages\WebDriver.IEDriverServer.win32.2.42.0\tools\install.ps1:9 char:1
+ $pi = $project.ProjectItems.Item($file.Name);
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ComMethodTargetInvocation

The ProjectItems.AddFromFile api does return an item ProjectItems | Select Name does not.

2
What does $file.Name return? - Lasse V. Karlsen
$file.Name returns IEDriverServer.exe - I've found the issue. I'll be updating the Question in a moment. - JJS

2 Answers

1
votes

I'm a owner of the other NuGet package for installing Selenium IEDriver.

I'm trying to resolve this issue on my NuGet package project, and publish Beta version today.

https://www.nuget.org/packages/Selenium.WebDriver.IEDriver/2.42.0.1-beta

My strategy is using Microsoft.Build class library, and treat CSPROJ as a MSBuild script XML instead of EnvDTE object model when detected the case of this issue.

By the way, my NuGet package "Selenium.WebDriver.IEDriver" does not contain IEDriverServer.exe. It is only downloading the driver from orignal publishing point during the build process. This means you need internet access to succesfully build the project.


For more information, please visit issue thread on GitHub: https://github.com/SeriousM/WebDriver.IEDriverServer-nuget/issues/1

0
votes

The issue was having the packages folder in the same directory as the csproj file.

The original setup was this:

C:\DEV\ATTACHMENTUNITTESTS\
+---.nuget\
+---AttachmentUnitTests.sln
+---AttachmentUnitTests.csproj
+---packages\
    \---WebDriver.IEDriverServer.win32.2.42.0\

AttachmentUnitTests.csproj has this incorrect ItemGroup entry

<ItemGroup>
  <Content Include="packages\WebDriver.IEDriverServer.win32.2.42.0\content\IEDriverServer.exe" />
</ItemGroup>

Changing the structure so that the CSPROJ was in it's own subdirectory made the issue go away.

C:\DEV\ATTACHMENTUNITTESTS\
+---.nuget\
+---AttachmentUnitTests.sln
+---AttachmentUnitTests\
|   +---Packages.config
|   \---AttachmentUnitTests.csproj
+---packages\
    \---WebDriver.IEDriverServer.win32.2.42.0\

AttachmentUnitTests.csproj has this correct ItemGroup entry

<ItemGroup>
  <Content Include="..\packages\WebDriver.IEDriverServer.win32.2.42.0\content\IEDriverServer.exe">
    <Link>IEDriverServer.exe</Link>
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  </Content>
</ItemGroup>

The fix for this issue is to move the CSPROJ to a sufolder that does not include the Packages folder.

I was able to get the original install working fine using a modified install.ps1, which illustrates that the issue because

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

$file = Join-Path (Join-Path $toolsPath '..\content') 'IEDriverServer.exe' | Get-ChildItem
# IEDriverServer.exe is copied to the project root because it's in the content folder of the nupkg
# this line will always work because the file exists as a copy in the root of the project
$project.ProjectItems.Item($file.Name).Delete()

# now we want to re-add it as a linked item in the Packages folder
$pi = $project.ProjectItems.AddFromFile($file.FullName);
# reference the original item returned by AddFromFile, no need to go looking again
#$pi = $project.ProjectItems.Item($file.Name);
$pi.Properties.Item("BuildAction").Value = [int]2; 
#2 = prjBuildActionContent - The file is included in the Content project output group

...and this modified uninstall.ps1

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

# original code didn't work when packages\ is in same folder as csproj
#$file = Join-Path (Join-Path $toolsPath '..\content') 'IEDriverServer.exe' | Get-ChildItem
#$project.ProjectItems.Item($file.Name).Delete()

# don't show nasty red warnings.
$ErrorActionPreference = "SilentlyContinue"
# create a variable with null value
$pi = $null
# does
$pi = $project.ProjectItems.Item($file.Name)
if $pi -eq $null then $pi = $project.ProjectItems.Item("packages").ProjectItems.Item($package).ProjectItems.Item("content").ProjectItems.Item("IEDriverServer.exe")
if $pi -ne $null then $pi.Delete()