0

デバッグ/テスト用のApp.configファイルからエンドユーザーのマシン上の最終的なホームへのパスをいくつか変更する必要があります。Visual Studioを使用してインストーラープロジェクトを編集すると、[XMLファイルの変更]オプションが表示されます。ヘルプには、変更するxmlファイルをインポートする必要があることが示されています。

しかし...

XMLファイルのプロジェクトの出力をインポートする方法はありますか?ファイル自体を直接参照する場合は、デバッグまたはリリースの構成ファイルを使用する必要がありますが、これは煩わしいようです。それ以外の場合は、基本のApp.configを使用できますが、ビルド時に変換が適用されると、それらは失われます。

それで、私はファイルを参照するだけで立ち往生していますか、それとも.exeファイルの場合と同じように「プロジェクト出力」を取得できますか?

4

3 に答える 3

1

動作するはずのように見えますが、Installshield はプロジェクト出力を正しく grok できません (依存関係が頻繁に見落とされ、適用されない場合でもマージ モジュールが複製されます)、またはプロジェクト出力内の個々のファイルを処理する方法が提供されます。

プロジェクト出力の使用に関する問題について 5 つ以上のバグが開いており、回避策は常に「ファイルを手動で追加する」ことです。

インストール シールドを使い始めたばかりの場合は、別の方法を試すことをお勧めします。それを使用する必要がある場合は、これが機能しないことについてサポート チームに苦情を言い、彼らが解決するまで提案された回避策を使用してください。

これはあなたの質問に対する「答え」ではないかもしれませんが、この製品の壊れた機能セットに対処する際の正気に役立つことを願っています。

于 2012-08-10T15:30:32.613 に答える
1

XML ファイルの変更はかなり弱いお茶です。探していることを実行するには、InstallShield の外部で .config ファイルをロードして更新するカスタム アクションを作成する必要があります。

2012 C# Wizard プロジェクト タイプを使用している場合、オプションは After Move Data で OnEnd() イベントをキャッチする .rul を作成することです。.rul から UseDLL を介して dll を呼び出し、config へのターゲット パスと値を更新する値を受け入れるメソッドを呼び出します。

以下は私がテストしているコードです... C# ウィザード プロジェクト タイプを使用して、C# dll を呼び出すために次の InstallScript ルールを追加しました。

function OnEnd()
string basePath;
BOOL bResult;
string dllPath;
OBJECT oAppConfig;
begin

dllPath = TARGETDIR ^ APPCONFIG_DLL;
try
    set oAppConfig = DotNetCoCreateObject(dllPath, "AppConfig.ConfigMgr", "");
catch
    MessageBox("Error Loading" + dllPath + ": "  + Err.Description, INFORMATION); 
    abort;
endcatch;

try
    basePath = "C:\\Program Files (x86)\\MyCompany\\Config Test\\";
    bResult = oAppConfig.ConfigureSettings(basePath + "appsettings.xml", basePath + "app.config", "someAppSection");
catch
    MessageBox("Error calling ConfigureSettings " + dllPath + " " + Err.Number + " " + Err.Description, INFORMATION);
endcatch;

end;

C# テスト コード: public bool ConfigureSettings(string configFilePath, string targetAppConfigPath, string targetAppName) { bool completed = true;

        try
        {
            XmlDocument configFileDoc = new XmlDocument();
            configFileDoc.Load(configFilePath);

            string installerTargetFileDoc = targetAppConfigPath; // InstallShield's build process for Visual Studio solutions does not rename the app.config file - Awesome!
            System.IO.FileInfo fi = new System.IO.FileInfo(installerTargetFileDoc);
            if (fi.Exists == false) installerTargetFileDoc = "app.config";
            XmlDocument targetAppConfigDoc = new XmlDocument();
            targetAppConfigDoc.Load(installerTargetFileDoc);

            // ensure all required keys exist in the target .config file
            AddRequiredKeys(configFileDoc.SelectSingleNode("configuration/" + targetAppName + "/requiredKeys"), ref targetAppConfigDoc);

            // loop through each key in the common section of the configuration file
            AddKeyValues(configFileDoc.SelectSingleNode("configuration/common/appSettings"), ref targetAppConfigDoc);

            // loop through each key in the app specific section of the configuration file - it will override the standard configuration
            AddKeyValues(configFileDoc.SelectSingleNode("configuration/" + targetAppName + "/appSettings"), ref targetAppConfigDoc);

            // save it off
            targetAppConfigDoc.Save(targetAppConfigPath);
        }
        catch (Exception ex)
        {
            completed = false;
            throw ex;
        }
        return completed;
    }
    private void AddKeyValues(XmlNode configAppNodeSet, ref XmlDocument targetAppConfigDoc)
    {
        foreach (XmlNode configNode in configAppNodeSet.SelectNodes("add"))
        {
            XmlNode targetNode = targetAppConfigDoc.SelectSingleNode("configuration/appSettings/add[@key='" + configNode.Attributes["key"].Value + "']");
            if (targetNode != null)
            {
                targetNode.Attributes["value"].Value = configNode.Attributes["value"].Value;
            }
        }
    }
    private void AddRequiredKeys(XmlNode targetAppNodeSet, ref XmlDocument targetAppConfigDoc)
    {
        foreach (XmlNode targetNode in targetAppNodeSet.SelectNodes("key"))
        {
            // add the key if it doesn't already exist
            XmlNode appNode = targetAppConfigDoc.SelectSingleNode("configuration/appSettings/add[@key='" + targetNode.Attributes["value"].Value + "']");
            if (appNode == null)
            {
                appNode = targetAppConfigDoc.SelectSingleNode("configuration/appSettings");
                XmlNode newAddNode = targetAppConfigDoc.CreateNode(XmlNodeType.Element, "add", null);
                XmlAttribute newAddNodeKey = targetAppConfigDoc.CreateAttribute("key");
                newAddNodeKey.Value = targetNode.Attributes["value"].Value;
                XmlAttribute newAddNodeValue = targetAppConfigDoc.CreateAttribute("value");
                newAddNodeValue.Value = "NotSet";
                newAddNode.Attributes.Append(newAddNodeKey);
                newAddNode.Attributes.Append(newAddNodeValue);
                appNode.AppendChild(newAddNode);
            }
        }
    }

于 2012-06-21T00:34:53.637 に答える
0

必要なファイルを (ブラウズして) インポートし、実行時の任意の場所で変更を加えることができます。変更を加えるために必要な最小限の量を入れることをお勧めします。結局のところ、それは XML ファイルの変更ビューです。そうすれば、ファイルがどのように含まれているかに関係なく、ほとんどのファイルの更新によって、XML ファイルの変更設定が変更されたり、変更が必要になったりすることはありません。

于 2012-05-03T23:54:30.803 に答える