.NET 程序下銳浪報表 (Grid++ Report) 的綠色發佈指南

.NET 程序下銳浪報表 (Grid++ Report) 的綠色發佈指南html

在銳浪報表官方爲 CSharp 編寫的開發文檔:「在C#與VB.NET中開始使用說明.txt」 中,關於發佈項目是這麼描述的:git

★發佈你的項目,用VS.NET製做安裝程序:
一、先建立安裝項目:在解決方案資源管理器的根節點上點右鍵,在彈出的菜單裏執行「添加->新建項目…」,建立一個「安裝項目」。
二、加入項目發佈文件:在解決方案資源管理器的新建立的安裝項目節點上點右鍵,在彈出的菜單裏執行「添加->項目輸出…」,在打開的窗口裏選擇「主輸出」,這樣能夠把程序的發佈文件自動加入到安裝項目中。
三、設置Grid++Report的DLL文件爲COM自注冊:分別設置「gregn6.dll」與「grdes6.dll」的「Register」屬性爲「vsdrfCOMSelfReg」。es6

C:\Grid++Report 6\Samples\CSharp\在C#與VB.NET中開始使用說明.txt

這種方式須要咱們在運行程序以前將 Grid++Report 依賴的 COM 組件註冊到操做系統中。有沒有辦法能夠作到綠色發佈呢?windows

以 C:\Grid++Report 6\Samples\CSharp\1.Tutorial\PrintReport\PrintReport.sln 項目爲例,咱們對項目進行改造,使其支持綠色發佈( xcopy-deploy):app

  1. 在項目中增長 Files 文件夾
  2. 將項目依賴的數據文件 1a.簡單表格.grf 和 Northwind.mdb 複製到 Files 文件夾,並設置文件屬性 「複製到輸出目錄」 爲 「始終複製」。
  3. 將 C:\Grid++Report 6\ 目錄下的 「gregn6.dll」與「grdes6.dll」 複製到項目中,並設置文件屬性 「複製到輸出目錄」 爲 「始終複製」。

作完以上三步,解決方案管理器看上去應該是這個樣子:(筆者對源文件進行了一些改動,並將 Form1 重命名爲了 FrmMain 。)ide

接着,對代碼進行改造,使其從程序所在目錄讀取數據,而不是 Grid++Report 的安裝目錄:函數

 public FrmMain() { // // Windows 窗體設計器支持所必需的 // InitializeComponent(); // // TODO: 在 InitializeComponent 調用後添加任何構造函數代碼 // //載入報表模板文件,必須保證 Grid++Report 的安裝目錄在‘C:\Grid++Report 6’下, //關於動態設置報表路徑與數據綁定參數請參考其它例子程序 var dir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Files"); Report.LoadFromFile(Path.Combine(dir, "1a.簡單表格.grf")); Report.DetailGrid.Recordset.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;" + @"User ID=Admin;Data Source=" + Path.Combine(dir, "Northwind.mdb"); }

若是你在電腦中安裝了最新版的 Grid++Report ,那麼你會有如下目錄:C:\Grid++Report 6\manifest測試

本目錄下的兩個 .manifest 文件爲Grid++Report的發佈DLL的清單模板文件,利用這兩個文件並適當調整能夠實現免DLL註冊發佈用Grid++Report開發的軟件,實現綠色發佈。
更詳細說明請參考幫助文檔的「報表組件(C/S報表)->發佈軟件->免註冊發佈(推薦方式)」部分。
YourX86.exe.manifest:32位程序清單文件模板
YourX64.exe.manifest:64位程序清單文件模板ui

C:\Grid++Report 6\manifest\readme.txt

在項目中添加一個新建項 「應用程序清單文件」:spa

以後須要打開 YourX86.exe.manifest 文件,並將兩個 file 標籤的內容複製到項目的 app.manifest 文件中。這個操做完成後,app.manifest 的代碼以下:

<?xml version="1.0" encoding="utf-8"?> <assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1"> <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/> <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"> <security> <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3"> <!-- UAC 清單選項 若是想要更改 Windows 用戶賬戶控制級別,請使用 如下節點之一替換 requestedExecutionLevel 節點。n <requestedExecutionLevel level="asInvoker" uiAccess="false" /> <requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> <requestedExecutionLevel level="highestAvailable" uiAccess="false" /> 指定 requestedExecutionLevel 元素將禁用文件和註冊表虛擬化。 若是你的應用程序須要此虛擬化來實現向後兼容性,則刪除此 元素。 --> <requestedExecutionLevel level="asInvoker" uiAccess="false" /> </requestedPrivileges> </security> </trustInfo> <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> <application> <!-- 設計此應用程序與其一塊兒工做且已針對此應用程序進行測試的 Windows 版本的列表。取消評論適當的元素, Windows 將自動選擇最兼容的環境。 --> <!-- Windows Vista --> <!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />--> <!-- Windows 7 --> <!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />--> <!-- Windows 8 --> <!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />--> <!-- Windows 8.1 --> <!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />--> <!-- Windows 10 --> <!--<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />--> </application> </compatibility> <!-- 指示該應用程序能夠感知 DPI 且 Windows 在 DPI 較高時將不會對其進行 自動縮放。Windows Presentation Foundation (WPF)應用程序自動感知 DPI,無需 選擇加入。選擇加入此設置的 Windows 窗體應用程序(目標設定爲 .NET Framework 4.6 )還應 在其 app.config 中將 "EnableWindowsFormsHighDpiAutoResizing" 設置設置爲 "true"。--> <!-- <application xmlns="urn:schemas-microsoft-com:asm.v3"> <windowsSettings> <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware> </windowsSettings> </application> --> <!-- 啓用 Windows 公共控件和對話框的主題(Windows XP 和更高版本) --> <!-- <dependency> <dependentAssembly> <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*" /> </dependentAssembly> </dependency> --> <file name="grdes6.dll"> <typelib tlbid="{c5a16330-a084-48c9-bc0f-0d0b37a14123}" version="6.0" helpdir="" resourceid="0" flags="HASDISKIMAGE" /> <comClass clsid="{6edd80cb-9f08-4c71-b406-479e5cb80fce}" threadingModel="Apartment" tlbid="{c5a16330-a084-48c9-bc0f-0d0b37a14123}" progid="grdes.GRDesigner.6" description="Grid++Report Designer 6" /> </file> <file name="gregn6.dll"> <typelib tlbid="{4018f953-1bfe-441e-8a04-dc8ba1ff060e}" version="6.0" helpdir="" resourceid="0" flags="HASDISKIMAGE" /> <comClass clsid="{f9364159-6aed-4f9c-8baf-d7c7ed6160a8}" threadingModel="Apartment" tlbid="{4018f953-1bfe-441e-8a04-dc8ba1ff060e}" progid="gregn.GridppReport.6" description="GridppReport Class" /> <comClass clsid="{1b5ea181-a38d-4f42-88b2-6af74cf6d6c0}" threadingModel="Apartment" tlbid="{4018f953-1bfe-441e-8a04-dc8ba1ff060e}" progid="gregn.GRDisplayViewer.6" description="Grid++Report DisplayViewer 6" /> <comClass clsid="{7fd5dc62-ded0-4138-9c48-55f0a0fe7b66}" threadingModel="Apartment" tlbid="{4018f953-1bfe-441e-8a04-dc8ba1ff060e}" progid="gregn.GRDisplayViewerProps.6" description="GRDisplayViewerProps Class" /> <comClass clsid="{44cbb5de-5afb-4c3d-8f3f-0f70ca5372ad}" threadingModel="Apartment" tlbid="{4018f953-1bfe-441e-8a04-dc8ba1ff060e}" progid="gregn.GRPrintViewer.6" description="Grid++Report PrintViewer 6" /> <comClass clsid="{6ca58cb2-2ad1-4ad0-b3cc-5f5c000bbdee}" threadingModel="Apartment" tlbid="{4018f953-1bfe-441e-8a04-dc8ba1ff060e}" progid="gregn.GRPrintViewerProps.6" description="GRPrintViewerProps Class" /> </file> </assembly>

至此,咱們就能夠在不註冊 COM 組件的狀況下使用 Grid++Report 了。

本文所涉及的代碼能夠在 Gitee 上找到: https://gitee.com/coderbusy/demo/tree/master/gridpp_xcopy 。

相關文章
相關標籤/搜索