C#程式集系列08,設定程式集版本

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   os   使用   ar   strong   


區別一個程式集,不僅僅是程式集名稱,還包括程式集版本、程式集公匙、程式集文化等,本篇體驗通過介面和編碼設定程式集版本。

 

□ 通過Visual Studio設定程式集版本

→右鍵項目,選擇"屬性",選擇"應用程式"
→點擊"程式集資訊",設定如下,點擊確定

→點擊項目Properties檔案夾下的AssemblyInfo.cs,可以看到程式集版本已經設定生效
[assembly: AssemblyVersion("3.3.3.3")]

 

□ 通過編碼設定程式集版本

→在F盤的as檔案夾下建立Cow.cs檔案
→用記事本開啟Cow.cs,編寫如下,儲存

using System;
using System.Reflection;
[assembly: AssemblyVersion("3.3.3.3")]
public class Cow
{
    public static void Moo()
    {
        Console.WriteLine("Moo version 1");
    }
}


→把Cow.cs編譯成程式集

→在F盤的as檔案夾下建立MainClass.cs檔案

using System;
class MainClass
{
    static void Main()
    {
        Cow.Moo();
    }
}


→編譯MainClass,引用Cow.dll,產生MainClass.exe檔案

→運行MainClass.exe

→現在要試著篡改程式集,先刪除Cow.dll
→在F盤的as檔案夾下建立AnotherCow.cs檔案
→用記事本開啟AnotherCow.cs,編寫如下,儲存

using System;
using System.Reflection;
[assembly: AssemblyVersion("8.8.8.8")]
public class Cow
{
    public static void Moo()
    {
        Console.WriteLine("Moo version 2");
    }
}

以上,同Cow.cs相比,修改了程式集的版本以及方法的實現。
→編譯AnotherCow.cs,重建Cow.dll程式集

→反編譯Cow.dll來查看程式集的版本

.assembly Cow
{
  .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) 
  .custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78   // ....T..WrapNonEx
                                                                                                             63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 )       // ceptionThrows.
  .hash algorithm 0x00008004
  .ver 8:8:8:8
}

○ .ver 8:8:8:8程式集版本發生了改變,原先是.ver 3:3:3:3

→運行MainClass.exe

 

總結:可以通過介面或編碼設定程式集版本號碼;通過更新程式集來更新應用程式。

 

“C#程式集系列”包括:

  C#程式集系列01,用記事本編寫C#,IL代碼,用DOS命令編譯器集,運行程式  C#程式集系列02,使用記事本查看可執行程式集的IL代碼  C#程式集系列03,引用多個module  C#程式集系列04,在程式集包含多個module的情境下理解關鍵字internal  C#程式集系列05,讓程式集包含多個module  C#程式集系列06,資訊清單,EXE和DLL的區別  C#程式集系列07,篡改程式集  C#程式集系列08,設定程式集版本

 

 

參考資料:

http://www.computersciencevideos.org/  created by Jamie King

C#程式集系列08,設定程式集版本

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.