Visual Studio 12 VSIXInstaller 在 DSC 脚本中 运行 时报告 FileNotFoundException
Visual Studio 12 VSIXInstaller reports a FileNotFoundException when running in DSC Script
我正在编写 Powershell DSC 脚本,以便轻松配置开发环境。我试图在不打开 GUI 的情况下安装 Visual Studio 2012 Addons。
我已经下载了 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 Install-VSIX cmdlet 尝试了以下操作:
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 }
}
在这种情况下,命令完成,但 VSIXInstall.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 执行它。
通过 DSC Set-Script 脚本 运行ning 显然有些不同。任何想法如何修复它?或者其他方法?
VSIX 是针对每个用户的,您需要使用 PSDscRunAsCredential
(在 PowerShell 5.0 中添加)告诉 DSC 哪个用户安装它。
示例,其中 $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
}
另请参阅 Securing the MOF
File,了解如何正确加密 MOF
文件,以免泄露您的凭据。
我正在编写 Powershell DSC 脚本,以便轻松配置开发环境。我试图在不打开 GUI 的情况下安装 Visual Studio 2012 Addons。
我已经下载了 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 Install-VSIX cmdlet 尝试了以下操作:
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 }
}
在这种情况下,命令完成,但 VSIXInstall.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 执行它。
通过 DSC Set-Script 脚本 运行ning 显然有些不同。任何想法如何修复它?或者其他方法?
VSIX 是针对每个用户的,您需要使用 PSDscRunAsCredential
(在 PowerShell 5.0 中添加)告诉 DSC 哪个用户安装它。
示例,其中 $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
}
另请参阅 Securing the MOF
File,了解如何正确加密 MOF
文件,以免泄露您的凭据。