項目的背景、需求收集、設計等涉及商業隱私,所以這些內容不是本欄目的重點。
主結構
由於主要是我一個人開發,而且目前也不涉及數據庫操作,所以沒有經典三層或是其它高大上的結構。
global文件夾中存放的是一些跟.sln文件同級的文件,包括.gitignore、Directory.Build.props、 發布腳本、清理腳本等文件。
Directory.Build.props
介紹:https://docs.microsoft.com/en-us/visualstudio/msbuild/customize-your-build
Prior to MSBuild version 15, if you wanted to provide a new, custom property to projects in your solution, you had to manually add a reference to that property to every project file in the solution. Or, you had to define the property in a .props file and then explicitly import the .props file in every project in the solution, among other things.
However, now you can add a new property to every project in one step by defining it in a single file called Directory.Build.props in the root folder that contains your source. When MSBuild runs, Microsoft.Common.props searches your directory structure for the Directory.Build.props file (and Microsoft.Common.targets looks for Directory.Build.targets). If it finds one, it imports the property. Directory.Build.props is a user-defined file that provides customizations to projects under a directory.
大致意思是為目錄下的所有項目提供一致的項目配置。
比如 ,我這個解決方案中就是用這個文件來統一我所有Project的輸出版本號。
1 <Project> 2 <PropertyGroup> 3 <LangVersion>latest</LangVersion> 4 <Description>*******</Description> 5 <Version>1.0.0.0</Version> 6 <Company>****</Company> 7 <Copyright>Copyright © **** 2019</Copyright> 8 9 <Configurations>Debug;Release;Business_User;AI_User;IDUU_User</Configurations> 10 </PropertyGroup> 11 12 <!--Debug:客戶端開發者--> 13 <PropertyGroup Condition="'$(Configuration)'=='Debug'"> 14 <DefineConstants>TRACE;DEBUG</DefineConstants> 15 <DebugType>full</DebugType> 16 <DebugSymbols>true</DebugSymbols> 17 </PropertyGroup> 18 19 <!--Release:客戶端開發者、后端維護人員--> 20 <PropertyGroup Condition="'$(Configuration)'=='Release'"> 21 <Optimize>true</Optimize> 22 <DefineConstants>TRACE;RELEASE</DefineConstants> 23 </PropertyGroup> 24 25 <!--Business_User:業務配置人員--> 26 <PropertyGroup Condition="'$(Configuration)'=='Business_User'"> 27 <Optimize>true</Optimize> 28 <DefineConstants>TRACE;USER;Business_USER</DefineConstants> 29 </PropertyGroup> 30 31 <!--AI_User:通用用戶--> 32 <PropertyGroup Condition="'$(Configuration)'=='AI_User'"> 33 <Optimize>true</Optimize> 34 <DefineConstants>TRACE;USER;AI_USER</DefineConstants> 35 </PropertyGroup> 36 37 <!--IDUU_User:高級用戶--> 38 <PropertyGroup Condition="'$(Configuration)'=='IDUU_User'"> 39 <Optimize>true</Optimize> 40 <DefineConstants>TRACE;USER;IDUU_USER</DefineConstants> 41 </PropertyGroup> 42 </Project>
可以看出,在上面的文件中,我定義了很多項目配置項,如:Debug;Release;Business_User;AI_User
它們的作用是方便我在publish時可以根據不同的使用者生成不同的客戶端。
Publish.ps1
1 #准備工作 2 #更新包管理平台 3 #Install-PackageProvider -Name NuGet -Force 4 #Install-Module -Name PowerShellGet -Force 5 #或 6 #Update-Module -Name PowerShellGet 10 11 #請在src目錄執行此腳本 12 13 $publish_home=[System.IO.Path]::Combine((Get-Location).Path,"Publish\") 14 #$7z="D:\Program Files\7-Zip\7z.exe" 15 $7z="C:\Program Files\7-Zip\7z.exe" 16 $version=([xml](Get-Content Directory.Build.props -encoding utf8)).Project.PropertyGroup[0].Version 17 18 Function Build([string]$configuration,[string]$zipFileHead,[string]$ext=".7z") 19 { 20 $dir=[System.String]::Format("{0}_{1}",$zipFileHead,$version) 21 $full_path=$publish_home+$dir 22 $csproj='.\SpiderX\SpiderX.csproj' 23 24 Write-Host ([System.String]::Format("構建 {0} 版本中...",$configuration)) 25 dotnet build -c $configuration $csproj 26 Write-Host ([System.String]::Format("發布 {0} 版本中...",$configuration)) 27 dotnet publish --configuration $configuration --framework net472 --runtime win7-x86 --output $full_path $csproj 28 29 $file_full_path=$full_path+$ext 30 31 Write-Host "打包文件中..." 32 &$7z a $file_full_path $full_path 33 } 34 35 Function BuildActivator([string]$configuration,[string]$zipFileHead,[string]$ext=".7z") 36 { 37 $dir=[System.String]::Format("{0}_{1}",$zipFileHead,$version) 38 $full_path=$publish_home+$dir 39 $csproj='.\SpiderX.AdvActivator\SpiderX.AdvActivator.csproj' 40 41 Write-Host ([System.String]::Format("構建 {0} 版本中...",$configuration)) 42 dotnet build -c $configuration $csproj 43 Write-Host ([System.String]::Format("發布 {0} 版本中...",$configuration)) 44 dotnet publish -c $configuration --self-contained false --output $full_path $csproj 45 46 $file_full_path=$full_path+$ext 47 48 Write-Host "打包文件中..." 49 &$7z a $file_full_path $full_path 50 } 51 52 #--------------清空文件夾-----------------# 53 if(Test-Path $publish_home) 54 { 55 Write-Host "清空`發布`文件夾" 56 Get-ChildItem $publish_home | Remove-Item -Recurse 57 } 58 59 #--------------AI/BI-----------------# 60 Build "AI_User" "****" 61 62 #--------------打開`發布`文件夾-----------------# 63 explorer.exe ("/root,"+$publish_home) 64 65 #--------------IDUU-----------------# 66 Build "IDUU_User" "****_IDUU" ".zip" 67 68 #--------------高級-----------------# 69 Build "Release" "****_DEV" 70 71 #--------------業務SQL-----------------# 72 Build "Business_User" "****_SQL" 73 74 #--------------激活碼簽發工具-----------------# 75 BuildActivator "Release" "****_Activator" 76 77 Write-Host "發布成功!"
powershell是個好東西。由於需要部署的用戶群體較多,暴露的客戶端標識也較多,如果手動發布,費事費力。如果編譯期間發生錯誤,還需要重新來一遍,所以我利用ps腳本寫了一個多版本發布工具,可以一鍵生成所有可用部署客戶端(帶版本號、帶部署標識),十分方便。
Clean.ps1
這也是一個powershell腳本,主要用來做一些清理工作。
TODO
這個文件主要記錄一些比較重要的TODO項。
可能有人會問,VS不是提供了TODO標記么,為什么還要專門自建一個markdown文檔:
1. 代碼中的TODO可能只是簡單的未實現功能,做個標記,有機會來補充。這個我平時也用,但是有些功能是一個比較大的規划,涉及多個模塊,非代碼層面,順手記在統一的文件中。在某個時間點,可以根據功能的優先級,來重新安排任務,這個非簡單的`//TODO`能做到的;
2. JIRA呢,可以記錄一些組織安排的比較重要的任務或bug,但是對自覺性比較高的某人來說,可能還需要另外一處地方來記錄問題。