โปรแกรมถ้าหากมีแก้ไขกันหลายๆ ครั้ง ก็ควรจะแสดงให้เห็นได้ง่าย ๆ ว่า user ใช้ version ไหนอยู่ จะได้ง่ายในการดูแล
การใส่ version ใน .Net จะเรียกว่า set assembly ทำได้ง่าย ๆ โดย
- ไปที่ Solution Explorer (ขวามือ)
- คลิกขวาตรง Project File (ใต้คำว่า Solution) เลือก Properties
- กรอกข้อมูล Assembly Name
- คลิก Assembly Information…
- ใส่เลข Assembly version: และข้อมูลอื่น ๆ
จากนั้นแก้ form ที่ต้องการให้แสดงเวอร์ชั่น โดยแทรก
AssemblyName thisAssemName = this.GetType().Assembly.GetName(); this.Text = thisAssemName.Name + " Version " + thisAssemName.Version;
เช่น FormMain.cs
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 ก็อาจจะแก้เป็น
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; } } } }
อ่านเพิ่มเติม