Powershell Visual Studio 12 VSIXInstaller在DSC脚本中运行时报告FileNotFoundException

Powershell Visual Studio 12 VSIXInstaller在DSC脚本中运行时报告FileNotFoundException,powershell,visual-studio-2012,dsc,Powershell,Visual Studio 2012,Dsc,我正在编写Powershell DSC脚本,以便轻松配置开发环境。我正在尝试在不打开GUI的情况下安装Visual Studio 2012插件 我已经下载了Specflow.vsix文件。当我跑的时候 & "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\VSIXInstaller.exe" /q C:\Users\Public\Downloads\TechTalk.SpecFlow.Vs2010Integ

我正在编写Powershell DSC脚本,以便轻松配置开发环境。我正在尝试在不打开GUI的情况下安装Visual Studio 2012插件

我已经下载了Specflow.vsix文件。当我跑的时候

 & "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\VSIXInstaller.exe" /q C:\Users\Public\Downloads\TechTalk.SpecFlow.Vs2010Integration.vsix
在Powershell命令提示符下,它工作正常。但是,如果我尝试在DSC脚本资源中执行相同的操作,就会遇到问题。将上述命令复制并粘贴到SetScript中会导致VSInstaller.exe中的命令永远不会完成

因此,基于Choco cmdlet,我尝试了以下方法:

在本例中,命令完成,但vsixanstall.exe抛出一个FileNotFound错误,我可以从C:\Windows\Temp中创建的日志中看到该错误\

1/18/2017 10:51:51 AM - Searching for applicable products...
1/18/2017 10:51:51 AM - Found installed product - Microsoft Visual Studio Professional 2012
1/18/2017 10:51:51 AM - System.IO.FileNotFoundException: The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
  at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
  at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
  at Microsoft.VisualStudio.Settings.ExternalSettingsManager.GetScopePaths(String applicationPath, String suffixOrName, String vsVersion, Boolean isLogged, Boolean isForIsolatedApplication)
  at Microsoft.VisualStudio.Settings.ExternalSettingsManager.CreateForApplication(String applicationPath)
 at VSIXInstaller.App.GetExtensionManager(SupportedVSSKU sku)
 at VSIXInstaller.App.GetExtensionManagerForApplicableSKU(SupportedVSSKU supportedSKU, IInstallableExtension installableExtension, List`1 applicableSKUs)
 at VSIXInstaller.App.InitializeInstall()
 at VSIXInstaller.App.OnStartup(StartupEventArgs e)
文件肯定在那里;如果我向VSInstaller提供了一些不存在的东西,它会出现以下错误

1/18/2017 10:21:45 AM - VSIXInstaller.InvalidCommandLineException: Path to vsix file 'outfile' is invalid or you don't have required access permissions. Please check the path is valid and you have required access permissions.
该脚本正在使用Powershell 5的Windows 7 SP1虚拟机上本地运行。我正在使用具有管理员权限的Powershell ISE执行它


通过dscset脚本运行的脚本显然有些不同。有没有办法解决这个问题?还是另一种方法?

VSIX是针对每个用户的,您需要告诉DSC哪个用户使用
PSDscRunAsCredential
(在PowerShell 5.0中添加)安装此软件

例如,
$credential
是要为其安装VSIX的用户的凭据

Script installSpecflowVS {
        SetScript  = {          
            $specUrl  = 'https://visualstudiogallery.msdn.microsoft.com/9915524d-7fb0-43c3-bb3c-a8a14fbd40ee/file/79327/7/TechTalk.SpecFlow.Vs2010Integration.vsix'
            $outfile  = 'C:\Users\Public\DownloadsTechTalk.SpecFlow.Vs2010Integration.vsix'
            wget $specUrl -outfile $outfile 
            $psi = New-Object System.Diagnostics.ProcessStartInfo
            $psi.FileName='C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\VSIXInstaller.exe'
            $psi.Arguments="/q $outfile"
            $s = [System.Diagnostics.Process]::Start($psi)
            $s.WaitForExit()
            return $s.ExitCode
      }
      TestScript = { return $False }
      GetScript  = { return $True }
      PSDscRunAsCredential = $credential
}

另请参阅如何正确加密
MOF
文件,以免泄露您的凭据。

成功了吗?我也有同样的愿望。正在尝试为安装到Azure Automation帐户上的开发人员计算机编写DSC配置。
Script installSpecflowVS {
        SetScript  = {          
            $specUrl  = 'https://visualstudiogallery.msdn.microsoft.com/9915524d-7fb0-43c3-bb3c-a8a14fbd40ee/file/79327/7/TechTalk.SpecFlow.Vs2010Integration.vsix'
            $outfile  = 'C:\Users\Public\DownloadsTechTalk.SpecFlow.Vs2010Integration.vsix'
            wget $specUrl -outfile $outfile 
            $psi = New-Object System.Diagnostics.ProcessStartInfo
            $psi.FileName='C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\VSIXInstaller.exe'
            $psi.Arguments="/q $outfile"
            $s = [System.Diagnostics.Process]::Start($psi)
            $s.WaitForExit()
            return $s.ExitCode
      }
      TestScript = { return $False }
      GetScript  = { return $True }
      PSDscRunAsCredential = $credential
}