2016-04-25 11 views
5

PowerShell v5.0.10586.117にアップグレードしましたが、私のapp.configファイルからAppSettingsにアクセスできません。このコードはPowerShell v4で動作します(v4がインストールされている他のコンピュータでも試してみましたが、AppSettingsからデータを返します)。 PowerShell 5 AppSettingsバグ?

は、私はPowerShellの

[System.AppDomain]::CurrentDomain.SetData("APP_CONFIG_FILE", $AppConfigPath) 

私は、現在のドメインが

[System.AppDomain]::CurrentDomain.GetData("APP_CONFIG_FILE") 

戻りPATH\App.config が、私は実行

でアプリの設定を持っていることを確認することができますでのApp Config]を設定します
[System.Configuration.ConfigurationManager]::AppSettings.count 

PowerShellのv5のリターン:0

が、PowerShellのV4にする(Windows 7は、Windows Server 2008 R2エンタープライズ、など)が返されます:5

をなぜ行動はPowerShellの4対のPowerShell 5で異なるのでしょうか?これはバグですか?どのようにアプリの設定の問題を解決するためのアイデア?

[詳細]

私は$ RETVALを使用して-Roundこの作品で

 $configFile = System.Configuration.ConfigurationManager]::OpenExeConfiguration([System.Configuration.ConfigurationUserLevel]::None) 
     $settings = $configFile.AppSettings.Settings 
     $retVal = $settings[$keyName].Value 
     $configFile.Save([System.Configuration.ConfigurationSaveMode]::Modified) 
     [System.Configuration.ConfigurationManager]::RefreshSection($configFile.AppSettings.SectionInformation.Name) 

と回避策やって試してみました

、私は私のAppSettingsからデータを取得することができます期待していますが、あとで、App Configデータが存在すると予想しているインポートしている.dllで失敗します。

[更新1]: Windows 8、Windows 8.1、およびServer 2012でPowerShell 5にアップグレードして同じ問題が発生しました。タイトルと問題の説明が、テストしたすべてのPowerShell 5インスタンスにあることを反映するように更新されました。

[更新2]:

パー@PetSerAlは、私は、configファイルを設定する前に、私はのAppSettingを取得しようとする場合、私はPowerShellのV4で同じ問題を持っていることを発見し

[System.Configuration.ConfigurationManager]::AppSettings 
[System.AppDomain]::CurrentDomain.SetData("APP_CONFIG_FILE", $AppConfigPath) 
[System.Configuration.ConfigurationManager]::AppSettings.Count 

PowerShell v4で0を返します。

私はC:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe.configに私のアプリの設定ファイルを移動した場合、私は、データを返す問題を持っていない、また私は、私はそれがアプリの設定

+0

'' [System.AppDomain] :: CurrentDomain.SetData( "APP_CONFIG_FILE"、$ AppConfigPath) 'の前にPowerShell v4で' [System.Configuration.ConfigurationManager] :: AppSettings'を最初に聞いた場合、同じ問題がありますか? – PetSerAl

+0

'[System.Configuration.ConfigurationManager] :: AppSettings'は、現在のドメインのapp設定ファイルで定義されているAppSettingsセクションを返します。アプリケーション設定ファイルを定義せずにAppSettingsを呼び出すと、デフォルトは 'C:\ Windows \ System32 \ WindowsPowerShell \ v1.0 \ powershell.exe 'になります。私がテストしたシステム上には存在しない「config」があります。それが存在しないので、AppSettingsセクションのために何も返されません。ファイルを作成しようとすることはできますが、テストしようとしていることはわかりません。 – rogergarrison

+0

'[System.Configuration.ConfigurationManager] :: AppSettings; [System.AppDomain] :: CurrentDomain.SetData( "APP_CONFIG_FILE"、$ AppConfigPath)。 [System.Configuration.ConfigurationManager] :: AppSettings'。 '[System.Configuration.ConfigurationManager] :: AppSettings'への2回目のアクセス時に、設定ファイルからデータを返しますか? – PetSerAl

答えて

1

に情報を期待してロードしていた外部のdllの問題を持っていますこれはPowerShell 5の以前のバージョンのバグのようです。私はPowerShell 5.1.14409.1005にアップグレードして以来、問題は解決されています。

関連する問題