指定程序集版本
// 1.0.0.0
var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
指定文件(产品)版本
string version = null;
var attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false);
if (attributes == null ||attributes.Length == 0)
{
version = "";
}
else
{
version = ((AssemblyFileVersionAttribute)attributes[0]).Version;
}
MSBuild脚本重新生成项目
@echo off
chcp 65001
:: MSBuild.exe 路径
set MSBUILD_PATH=C:Program Files (x86)Microsoft Visual Studio2019EnterpriseMSBuildCurrentBinMSBuild.exe
:: solution 路径
set SOLUTION_FILE=%rootPath%****.csproj
:: Release / Debug
set BUILD_CONFIG=Release
:: build / rebuild / clean
set BUILD_TYPE=Rebuild
:: AnyCPU / x64 / x86
set BUILD_PLATFORM=AnyCPU
:: OutputPath
set OUTPUT_PATH=%rootPath%in
@echo 编译开始
rd "%OUTPUT_PATH%"\%BUILD_CONFIG% /s/q
"%MSBUILD_PATH%" "%SOLUTION_FILE%" /t:%BUILD_TYPE% /p:Configuration=%BUILD_CONFIG%;Platform=%BUILD_PLATFORM%;OutDir="%OUTPUT_PATH%"\%BUILD_CONFIG% /m
::项目依赖项
set rootPath2=F:Src
"%MSBUILD_PATH%" "%rootPath2%依赖项目1.csproj" /t:%BUILD_TYPE% /p:Configuration=%BUILD_CONFIG%;Platform=%BUILD_PLATFORM%;OutDir="%OUTPUT_PATH%"\%BUILD_CONFIG%;WarningLevel=0 /clp:NoSummary;ShowTimestamp /verbosity:Quiet /m
"%MSBUILD_PATH%" "%rootPath2%依赖项目2.csproj" /t:%BUILD_TYPE% /p:Configuration=%BUILD_CONFIG%;Platform=%BUILD_PLATFORM%;OutDir="%OUTPUT_PATH%"\%BUILD_CONFIG%;WarningLevel=0 /clp:NoSummary;ShowTimestamp /verbosity:Quiet /m
@echo 编译结束
pause
bandizip新建压缩包
echo bandizip新建压缩包(覆盖已有文件)
set RAR_PATH=C:Program FilesBandizipBandizip.exe
::项目名称 1.11.0.20031315 Release.zip
set versionMain=1, 11, 0,
set hour=%time:~,2%
if "%time:~,1%"==" " set hour=0%time:~1,1%
set anotherVariable=%date:~5,2%%date:~8,2%%date:~11,2%%hour%
set RAR_NAME=项目名称 %versionMain%%anotherVariable% Release.zip
set RAR_NAME2=%RAR_NAME:, =.%
::Release压缩到当前目录 Bandizip.exe c **.zip c:src
"%RAR_PATH%" c "%OUTPUT_PATH%""%RAR_NAME2%" "%OUTPUT_PATH%"\%BUILD_CONFIG%
echo 打开目录
%SystemRoot%explorer.exe "%OUTPUT_PATH%"
pause