PlusMagi's Blog By Pitt Phunsanit C#,Programming C#: build .exe with version

C#: build .exe with version

ต้องเก็บไฟล์ที่ build ไฟล์เป็น version ต่าง ๆ ให้ user เอาไว้เทส ถ้านาน ๆ ทำทียังพอจะเปลี่ยนชื่อให้ได้ แต่ถ้าทำบ่อย ๆ คงจะน่าเบื่อ ให้คอมทำให้ซิ

เปิดไฟล์ *.csproj ใน folder ของ project ออกมาแก้ ปกติก็ใส่ไว้ท้าย ๆ ไฟล์

 <Target Name="GetAssmeblyVersion" AfterTargets="Build"> <GetAssemblyIdentity AssemblyFiles="$ (TargetPath) "> <Output TaskParameter="Assemblies" ItemName="MyAssemblyIdentities" /> </GetAssemblyIdentity> <Message Text="Assmebly Version: % (MyAssemblyIdentities.Version) " /> </Target> <Target Name="PostBuild" AfterTargets="GetAssmeblyVersion"> <Exec Command="copy /Y "$ (ProjectDir) $ (OutDir) \$ (TargetName) .exe" "$ (ProjectDir) $ (OutDir) \$ (TargetName) v.% (MyAssemblyIdentities.Version) _$ (ConfigurationName) .exe" " /> </Target> </Project>

หลังจาก build code ชุดนี้จะทำตามคำสังใน PostBuild ในที่นี้คือใช้ command copy .exe ตามปกติแล้วเพิ่ม version เข้าไปให้

ขอขอบคุณ

ป้ายกำกับ:,