Web ã¢ããªã±ã¼ã·ã§ã³ã®ããã¿ã¼ã«ããã¼ã¸ã§ã³æ å ±ã Git ã®ã³ãããããã·ã¥ãåãè¾¼ã¾ãã¦ããã®ãè¦ã¾ããã¡ãã£ã¨éãã¾ãããKudu ãã³ãããããã·ã¥ã表示ããã¦ã¾ãã
ASP.NET ã¢ããªã±ã¼ã·ã§ã³ã§ããåãããã«ãã¼ã¸ã§ã³ã¨ã³ãããããã·ã¥ã表示ããã¦ã¿ããã®ã§ãã³ãããããã·ã¥ãåãè¾¼ã 2 ã¤ã®æ¹æ³ã試ãã¦ã¿ã¾ããã
MSBuildTasks ã使ã
Web Deploy ã使ã£ã¦ Web Apps ã¸ãããã¤ããå ´åã«ã¯ãMSBuildTasks ã使ã£ã¦åãè¾¼ãããæ¹æ³ãããã¾ãããGitVersion ã¿ã¹ã¯ã§ã³ãããããã·ã¥ãåå¾ãã¦ãAssemblyInfo.cs ã丸ãã¨ä½æãã¾ãã
å®éã®æé ã¯ä»¥ä¸ã®ããã°ã«ã¨ã¦ãåãããããæ¸ãã¦ããã¾ãããMSBuild åå¿è ã§ãåãããããã
MSBuild: add git commit hash to AssemblyInfo · now from home
NuGet 㧠MSBuildTasks ãã¤ã³ã¹ãã¼ã«ããcsproj ãç·¨éãã¦ãã«ãããã¨åãè¾¼ã¾ãã¾ãã
å ¨ãæ°ãã AssemblyInfo.cs ãçæããã¦ãããã¨ã確èªã§ãã¾ãã
å®éã«ä½¿ãå ´åã«ã¯ .gitignore ã« AssemblyInfo.cs ãå ¥ãã¦ãããªãã¨ãæ¯åã³ããã対象ã«ãªã£ã¦ãã¾ã£ã¦ã¡ãã£ã¨ããã©ãããæãã§ããã
ã³ãããå¾ã«æ°ããã³ãããããã·ã¥ãåãè¾¼ã¾ããã®ã§ãããããªãæãã¯ãã¾ããç¥ããã«æ¾ç½®ãã¦ããã¨ãç¡éã«ã³ãããåºæ¥ã¦ãã¾ãããã§ããã
ã«ã¹ã¿ã ãããã¤ã¹ã¯ãªããã使ã
ã«ã¹ã¿ã ãããã¤ã¹ã¯ãªããå ã§ã¯ SCM_COMMIT_ID ã¨ããç°å¢å¤æ°ã§ããããã¤ãããã¨ãã¦ããã³ãããã®ããã·ã¥ãåããã®ã§ããããå©ç¨ã㦠AssemblyInfo.cs ã«ã³ãããããã·ã¥ãåãè¾¼ã¿ã¾ãã
ããã©ã«ãã®ããããã¡ã¤ã«ã ã¨å¦çã大å¤ãããã®ã§ãPowerShell ã§æ¸ãç´ãããã¼ã¸ã§ã³ã使ãã¾ãã
æ¢ã«è¨å®ããã¦ãã AssemblyVersion ãèªã¿åã£ã¦ããã®ãã¼ã¸ã§ã³ã«ã³ãããããã·ã¥ã追å ãããã®ã§ãæ£è¦è¡¨ç¾ã§ AssemblyInfo.cs ãããã¼ã¸ã§ã³ãæ½åºãã¾ãã
å®éã«æ¸ããã¹ã¯ãªããã¯ä»¥ä¸ã®ãããªæãã§ããã¤ãã¤ããªæãããã¾ãããåãã®ã§ã¾ãè¯ãã¨ãã¾ãã
$ASSEMBLY_INFO_PATH = "$DEPLOYMENT_SOURCE\WebApplication7\Properties\AssemblyInfo.cs" $ASSEMBLY_INFO_CONTENT = Get-Content $ASSEMBLY_INFO_PATH $ASSEMBLY_VERSION = [regex]::Match($ASSEMBLY_INFO_CONTENT, "AssemblyVersion\(`"(.+?)`"\)").Groups[1].Value $ASSEMBLY_INFORMATIONAL_VERSION = [string]::Format("[assembly: AssemblyInformationalVersion(`"{0}-{1}`")]", $ASSEMBLY_VERSION, $env:SCM_COMMIT_ID.Substring(0, 7)) Add-Content -Path $ASSEMBLY_INFO_PATH -Value $ASSEMBLY_INFORMATIONAL_VERSION
ããã deploy.ps1 ã® MSBuild å¼ã³åºãåã«è¿½å ãã¦ãWeb Apps ã«ããã·ã¥ããã¨åãè¾¼ã¾ãã¾ãã
Kudu ã使ã£ã¦ Web Apps ä¸ã®ãªãã¸ããªã確èªããã¨ãAssemblyInfo.cs ã«å±æ§ãåãè¾¼ã¾ãã¦ããã®ã確èªã§ãã¾ãããªãã¸ããªå ã®ãã¡ã¤ã«ãå¤æ´ãã¦ããKudu ãæ´æ°æã«é¢åã¿ã¦ãããã®ã§å¤§ä¸å¤«ã§ãã
ã³ãããããã·ã¥è¾¼ã¿ã®ãã¼ã¸ã§ã³ãåå¾ãã
æã¯ã«ã¹ã¿ã å±æ§ãåå¾ããã®ãããã©ãããã£ãè¨æ¶ãããã®ã§ããã.NET 4.5 ããã¯ã¸ã§ããªãã¯ã«å¯¾å¿ããæ¡å¼µã¡ã½ãããç¨æããã¦ããã¿ããã§ãã¨ã¦ãã·ã³ãã«ã«æ¸ããããã«ãªã£ã¦ãã¾ããã
CustomAttributeExtensions.GetCustomAttribute メソッド (System.Reflection) | Microsoft Learn
ãã®æ¡å¼µã¡ã½ããã使ã£ã¦ AssemblyInformationalVersion å±æ§ãåå¾ãã¦å¤ãåãåºãã¾ãã
// å®è¡ä¸ã®ã¢ã»ã³ããªãåå¾ var assembly = Assembly.GetExecutingAssembly(); // AssemblyInformationalVersion å±æ§ãåå¾ var assemblyInformationalVersion = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>(); // ex. 1.0.0.c33eac3 var informationalVersion = assemblyInformationalVersion.InformationalVersion;
ã«ã¹ã¿ã å±æ§ã¯å®è¡ä¸ã«å¤åãããã¨ããªãã®ã§ãã¢ããªã±ã¼ã·ã§ã³ã®åæåæã«åå¾ãã¦ããã¾ãããã
ããã£ã½ãããã¿ã¼ã«è¡¨ç¤ºãã¦ã¿ã¾ãããã©ã®ãã¼ã¸ã§ã³ã Web Apps ã«ãããã¤ããã¦ããã調ã¹ãããã«ã¯ãã¼ã¿ã«ã確èªãããããªãã£ãã®ã§ããã£ã¨ç¢ºèªåºæ¥ãããã«ãªãå°ã便å©ã«ãªãã¾ããã
ä»å㯠Git ã®ã³ãããããã·ã¥ã§ããããæ¥ä»ãä»ãããªã©å²ã¨èªç±ã«åºæ¥ã¾ãã