久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

從 Visual Studio 運行時,PowerShell 腳本結果不同

PowerShell script result different when ran from Visual Studio(從 Visual Studio 運行時,PowerShell 腳本結果不同)
本文介紹了從 Visual Studio 運行時,PowerShell 腳本結果不同的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我正在從 Visual Studio 2013 項目的 PostBuild 事件運行 PowerShell 構建腳本.
我為此使用的命令是(添加新行只是為了提高可讀性):

I'm running a PowerShell build script from the PostBuild event of a Visual Studio 2013 project.
The command I'm using for that is (new-lines added only for readability):

PowerShell -ExecutionPolicy ByPass -File "$(SolutionDir)..\build\build.ps1" 
  -SolutionFolder "$(SolutionDir)." -ProjectName "$(ProjectName)" 
  -OutputFolder "..\build\output" -ConfigurationName "$(ConfigurationName)"

此腳本的任務之一是查找本地 SQL Server 實例,以允許用戶附加所需的數據庫(如果它們不存在).
我正在使用以下 PowerShell 代碼來檢索本地實例:

One of the tasks of this script is to find local SQL Server instances to allow the user to attach required databases if they don't exist.
I'm using the following PowerShell code to retrieve the local instances:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SqlWmiManagement") | out-null
$m = New-Object ("Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer") "."

if ($m.ServerInstances -eq $null -or $m.ServerInstances.Length -eq $null -or $m.ServerInstances.Length -eq 0)
{
    throw New-Object [System.Exception] "No instances found."
}

$instances = $m.ServerInstances | % { ($_.Parent.Name + "\" + $_.Name) }

當我從命令行執行腳本時,這工作得很好,但是當我從 PostBuild 事件運行腳本時 $m.ServerInstances 返回 $null.

This is working perfectly fine when I execute the script from the command-line, but when I run the script from the PostBuild event $m.ServerInstances returns $null.

首先想到的是用戶權限,但我檢查了哪個用戶正在執行腳本,它在命令行和 VS PostBuild 中都是一樣的.

First thing that came to mind was user rights, but I checked which user is executing the script and it's the same in both command-line and VS PostBuild.

我還嘗試了一種從注冊表中檢索可用實例的不同方法(如此處),結果相同;從命令行運行時它工作正常,但從 VS PostBuild 運行時不返回任何實例.

I've also tried a different approach that retrieves the available instances from the registry (as described here), with the same result; it works fine when running from command-line, but returns no instances when running from VS PostBuild.

所以問題是,從命令行運行和導致這種不同行為的 VS PostBuild 有什么區別?

So the question is, what's the difference between running from command-line and VS PostBuild that is causing this different behaviour?

更新:
從 Visual Studio 運行時,腳本的其他部分會停止運行.
例如,從 cmd.exe 運行腳本時創建 IIS 網站工作正常,但從 VS PostBuild 運行時拋出異常:

UPDATE:
There are other parts of the script that stop functioning when running from Visual Studio.
For example creating an IIS website works fine when running the script from cmd.exe but throws an exception when ran from VS PostBuild:

Exception occurred while creating IIS site : 
  Retrieving the COM class factory for component with CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} 
  failed due to the following error : 
  80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

我嘗試了各種瘋狂的解決方法,例如使用 VS PostBuild 中的 cmd.exe/C 來執行 PowerShell 創建一個新的 PowerShell 腳本,該腳本調用 cmd.exe 來運行 PowerShell.
都給出相同的結果;該腳本在從命令提示符調用時有效,但在從 Visual Studio PostBuild 事件調用時無效.

I've tried all kinds of crazy workaround, like using cmd.exe /C from VS PostBuild to execute PowerShell create a new PowerShell script that calls cmd.exe to run PowerShell.
All give the same result; the script works when called from a command prompt, but not when called from a Visual Studio PostBuild event.

Visual Studio 本身以提升的權限運行.
也在沒有提升權限的情況下嘗試過,結果是同樣的問題.

Visual Studio itself is running with elevated permissions.
Also tried it without elevated permissions and that results in the same issue.

更新 2:
當我從命令提示符使用 MSBuild 構建解決方案以觸發調用腳本的 PostBuild 事件時,會出現同樣的問題

UPDATE 2:
The same problem occurs when I build the solution with MSBuild from a command prompt to trigger the PostBuild event that calls the script

推薦答案

事實證明,Visual Studio 始終執行 32 位 PowerShell 而不是 64 位.
即使我在 PostBuild 事件中指定了 PowerShell 的完整路徑,它仍然執行 32 位版本.

It turns out that Visual Studio always executes the 32-bit PowerShell instead of the 64-bit.
Even when I specified the full path to PowerShell in the PostBuild event, it still executed the 32-bit version.

這導致很多命令不起作用.
我通過使用以下命令調用 PowerShell 解決了這個問題:

That caused a lot of the commands not to work.
I solved it by calling PowerShell with this command:

%WINDIR%\SysNative\WindowsPowerShell\v1.0\PowerShell.exe

這會在我的機器上執行 64 位 PowerShell 并正常運行腳本.

That executes the 64-bit PowerShell on my machine and runs the script fine.

這篇關于從 Visual Studio 運行時,PowerShell 腳本結果不同的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

What SQL Server Datatype Should I Use To Store A Byte[](我應該使用什么 SQL Server 數據類型來存儲字節 [])
Interpreting type codes in sys.objects in SQL Server(解釋 SQL Server 中 sys.objects 中的類型代碼)
Typeorm .loadRelationCountAndMap returns zeros(Typeorm .loadRelationCountAndMap 返回零)
MS SQL: Should ISDATE() Return quot;1quot; when Cannot Cast as Date?(MS SQL:ISDATE() 是否應該返回“1?什么時候不能投射為日期?)
Converting the name of a day to its integer representation(將一天的名稱轉換為其整數表示)
How to convert nvarchar m/d/yy to mm/dd/yyyy in SQL Server?(如何在 SQL Server 中將 nvarchar m/d/yy 轉換為 mm/dd/yyyy?)
主站蜘蛛池模板: 日韩欧美亚洲 | 日日夜夜精品视频 | 91精品国产一区二区三区动漫 | 国产成人短视频在线观看 | 免费一区| 亚洲美女视频 | 国产综合精品一区二区三区 | 欧美一级在线观看 | 日韩中文一区二区 | 天堂网色 | 成年人视频在线免费观看 | 精品伊人久久 | 最近免费日本视频在线 | 国产精品免费一区二区三区 | 成人在线视频免费看 | 一级毛片视频 | 日本一二区视频 | 98久久 | 久久久免费| 欧美二区乱c黑人 | 91视频久久 | 男女下面一进一出网站 | 亚洲精品av在线 | 羞羞视频网站免费观看 | 一区二区三区视频在线免费观看 | 国产精品美女久久久久aⅴ国产馆 | 天堂综合 | 久久区二区 | 国产伦精品一区二区三区高清 | 午夜成人在线视频 | 国产三级电影网站 | 人人草天天草 | 国产小视频在线 | 一区二区三区免费在线观看 | 天天躁日日躁狠狠很躁 | 久久国产精品一区 | 亚洲精品高清视频在线观看 | 日韩免费一级 | 国产视频导航 | 日韩免费毛片视频 | 黄色大片视频 |