2011-11-09 244 views
27

我試圖爲Visual Studio Installer項目創建一個自定義操作來修改配置文件的權限。自定義操作 - 錯誤1001:找不到文件myApp.InstallState

的Installer.cs如下:

public override void Commit(IDictionary savedState) 
{ 
    base.Commit(savedState); 

    // Get path of our installation (e.g. TARGETDIR) 
    //string configPath = System.IO.Path.GetDirectoryName(Context.Parameters["AssemblyPath"]) + @"\config.xml"; 
    string configPath = @"C:\Program Files\Blueberry\Serial Number Reservation\config.xml"; 

    // Get a FileSecurity object that represents the current security settings. 
    FileSecurity fSecurity = File.GetAccessControl(configPath); 

    //Get SID for 'Everyone' - WellKnownSidType works in non-english systems 
    SecurityIdentifier everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null); 

    // Add the FileSystemAccessRule to the security settings. 
    fSecurity.AddAccessRule(new FileSystemAccessRule(everyone, FileSystemRights.Modify | FileSystemRights.Synchronize, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow)); 

    // Set the new access settings. 
    File.SetAccessControl(configPath, fSecurity); 

} 

public override void Install(IDictionary stateSaver) 
{ 
    base.Install(stateSaver); 
} 

public override void Rollback(IDictionary savedState) 
{ 
    base.Rollback(savedState); 
} 

public override void Uninstall(IDictionary savedState) 
{ 
    base.Uninstall(savedState); 
} 

然後,添加主輸出(Installer類=真)到安裝項目的自定義操作的提交部分。

當我運行安裝程序,我得到以下錯誤:

Error 1001: Could not find file 'c:\mypath\myapp.InstallState' 

精練我發現的相似經歷的幾個例子網頁,但沒有提供的解決方案都爲我工作。

任何想法?

回答

2

當安裝程序類未正確創建時,有時會發生這種情況。以下是可能對您有幫助的教程:http://devcity.net/Articles/339/1/article.aspx

確保您的自定義操作符合教程建議。

+0

這是我的情況,在自定義操作屬性中,當我需要它執行時,名爲InstallerClass的屬性被設置爲True - 因此將其更改爲False爲我做了訣竅。 –

+0

如果OP出現錯誤,並且更改InstallerClass屬性對我沒有任何影響 - 無論是在修復我的實際問題之前還是之後,這都是在我的CustomActionData值中修復缺少的引號。 – vapcguy

15

我沒有在我的安裝程序項目中爲所有四個覆蓋(安裝,卸載,提交和回滾)指定自定義操作時遇到此問題。只要我將項目輸出指定爲所有四項的自定義操作,問題就消失了。

在我的安裝程序類中,唯一的重寫是「Commit」和「Uninstall」;我認爲Install首先負責創建InstallState文件,並且因爲它從未被調用過,所以InstallState文件從未被創建過。

+0

當我收到你的帖子時,我確實嘗試了這個,但是IIRC它沒有工作。我覆蓋了所有4個覆蓋(儘管一對夫婦做得很少),但問題依然存在。不幸的是,我在發佈後的一週左右放棄了這個項目(長篇故事),所以我不可能回去報告解決方案。 – CJM

+1

爲我工作,只是將項目輸出添加到安裝自定義操作(而不是unintall或回滾)。當它僅被添加到提交自定義操作時,我得到錯誤1001。 – JimSTAT

+0

它適合我! – David

41

You can find a solution here

引述:

The problem is that the MSI infrastructure is looking for the installation state file which is usually created during the Install phase. If the custom action does not participate in the Install phase, no file is created.

The solution is to add the custom action to both the Install and the Commit phases, although it does nothing during the install phase.

+0

爲我工作。謝謝。 – AndrewS

+0

也爲我寫作。謝謝! +1 –

+0

謝謝你!幾個小時後,我的頭撞在牆上。得到了很好的解決。 – Tarik

3

有時候, 「Debugger.Launch();」放在那些被覆蓋的函數上進行調試。如果您在那裏安裝語句並在安裝過程中構建安裝程序,則會彈出一個對話框,詢問您是否需要調試,如果按'取消調試',則會出現此錯誤對話框。由於您在函數中添加了「Debugger.Launch()」,因此安裝程序會將該函數視爲「錯過」。所以,別忘了刪除它。

+0

我無恥複製的代碼中的調試器語句甚至沒有導致彈出,只是一個可悲的失敗,導致「InstallState找不到」,沒有任何明顯的原因浪費了我幾個小時的生命。 –

+0

啊,我犯了這個錯誤。謝謝! – David

+0

在這裏,我一遍又一遍地看着這個線程;不可思議,不可能是....非常感謝你! – MattCom

-2

嘗試在管理員命令提示符下安裝此項。這對我有效。

+0

這也適用於我。 –

0

嘗試在您的自定義操作的屬性中設置Installer class = false而不是true。這爲我解決了這個問題。

+0

1.不夠具體(哪個階段?你在你的Installer類中包含事件/重寫函數,你設置爲false的階段嗎?)2.我會說這必須是某種邊緣情況, t爲我工作,並且我的全部(每個階段)都設置爲True,沒有問題。 – vapcguy

0

對於我來說,這個問題是因爲只是在我的CustomActionData字符串添加文本框的名字圍繞着一個右引號一樣簡單。

我在用戶界面部分使用「文本框(A)」和「文本框(B)」窗口。 A有1個框,EDITA1,其中我得到文件的路徑,B有2個框,EDITB1EDITB2,用於某些數據庫參數。我CustomActionData字符串是這樣的:

/filepath="[EDITA1]" /host="[EDITB1] /port="[EDITB2]" 

它應該是:

/filepath="[EDITA1]" /host="[EDITB1]" /port="[EDITB2]" 

我用安裝覆蓋在我的Installer類(上[EDITB1]收盤報價)

得到值(即string filepath = Context.Parameters["filepath"];),並用它將它們寫入INI文件中,以便我的應用程序在安裝後使用。我在「自定義操作」GUI的所有階段下放置了「主要輸出」,但對InstallerClass屬性(默認值爲True)沒有做任何處理,只在安裝之一上設置了CustomActionData字符串。我甚至沒有在我的Installer類中包含重載函數,因爲我沒有在其他階段自定義任何東西。

相關問題