我正在尝试使用包管理器控制台安装此包。
https://www.nuget.org/packages/WebDriver.IEDriverServer.win32/
包裹经理: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;
错误:
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
ProjectItems.AddFromFile api会返回一个项目 ProjectItems |选择名称不会。
答案 0 :(得分:1)
我是另一个用于安装Selenium IEDriver的NuGet软件包的所有者。
我试图在我的NuGet包项目中解决此问题,并立即发布测试版。
https://www.nuget.org/packages/Selenium.WebDriver.IEDriver/2.42.0.1-beta
我的策略是使用Microsoft.Build类库,并在检测到此问题的情况时将CSPROJ视为MSBuild脚本XML而不是EnvDTE对象模型。
顺便说一句,我的NuGet包" Selenium.WebDriver.IEDriver"不包含IEDriverServer.exe。它只是在构建过程中从orignal发布点下载驱动程序。这意味着您需要访问Internet才能成功构建项目。
有关更多信息,请访问GitHub上的问题主题: https://github.com/SeriousM/WebDriver.IEDriverServer-nuget/issues/1
答案 1 :(得分:0)
问题是将packages文件夹放在与csproj文件相同的目录中。
最初的设置是:
C:\DEV\ATTACHMENTUNITTESTS\ +---.nuget\ +---AttachmentUnitTests.sln +---AttachmentUnitTests.csproj +---packages\ \---WebDriver.IEDriverServer.win32.2.42.0\
AttachmentUnitTests.csproj有不正确的 ItemGroup条目
<ItemGroup>
<Content Include="packages\WebDriver.IEDriverServer.win32.2.42.0\content\IEDriverServer.exe" />
</ItemGroup>
更改结构以便CSPROJ在其自己的子目录中使问题消失。
C:\DEV\ATTACHMENTUNITTESTS\ +---.nuget\ +---AttachmentUnitTests.sln +---AttachmentUnitTests\ | +---Packages.config | \---AttachmentUnitTests.csproj +---packages\ \---WebDriver.IEDriverServer.win32.2.42.0\
AttachmentUnitTests.csproj有正确 ItemGroup条目
<ItemGroup>
<Content Include="..\packages\WebDriver.IEDriverServer.win32.2.42.0\content\IEDriverServer.exe">
<Link>IEDriverServer.exe</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
此问题的解决方法是将CSPROJ移动到不包含Packages文件夹的sufolder。
我能够使用修改后的install.ps1让原始安装正常工作,这说明问题是因为
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
...并修改了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()