我正在编写一个Powershell DSC脚本,这样我就可以轻松地配置开发环境。我试图在不打开GUI的情况下安装Visual 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 安装-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设置脚本运行的脚本显然有一些不同之处。有什么办法修复它吗?还是另一种方法?
发布于 2017-01-24 00:39:48
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文件,以免泄露凭据。
https://stackoverflow.com/questions/41727414
复制相似问题