โปรแกรมถ้าหากมีแก้ไขกันหลายๆ ครั้ง ก็ควรจะแสดงให้เห็นได้ง่าย ๆ ว่า user ใช้ version ไหนอยู่ จะได้ง่ายในการดูแล
การใส่ version ใน .Net จะเรียกว่า set assembly ทำได้ง่าย ๆ โดย
- ไปที่ Solution Explorer (ขวามือ)
- คลิกขวาตรง Project File (ใต้คำว่า Solution) เลือก Properties
- กรอกข้อมูล Assembly Name
- คลิก Assembly Information…
- ใส่เลข Assembly version: และข้อมูลอื่น ๆ
จากนั้นแก้ form ที่ต้องการให้แสดงเวอร์ชั่น โดยแทรก
1 2 | AssemblyName thisAssemName = this .GetType().Assembly.GetName(); this .Text = thisAssemName.Name + " Version " + thisAssemName.Version; |
เช่น FormMain.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace PrototypeCSharp { public partial class FormMain : Form { public FormMain() { InitializeComponent(); AssemblyName thisAssemName = this .GetType().Assembly.GetName(); this .Text = thisAssemName.Name + " Version " + thisAssemName.Version; } } } |
เพิ่มเติม ถ้าต้องการแสดง environment ที่โปรแกรมกำลังใช้อยู่อาจจะเพิ่ม configurations ตามวิธี C#: Configurations ก็อาจจะแก้เป็น
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace PrototypeCSharp { public partial class FormMain : Form { public FormMain() { InitializeComponent(); AssemblyName thisAssemName = this .GetType().Assembly.GetName(); if (Configurations.environment == "PRODUCTION" ) { this .Text = thisAssemName.Name + " Version " + thisAssemName.Version; } else { this .Text = thisAssemName.Name + " Version " + thisAssemName.Version + " " + Configurations.environment; } } } } |
อ่านเพิ่มเติม