zoukankan      html  css  js  c++  java
  • 中型WPF客户端开发项目总结(3.1)

    项目的背景、需求收集、设计等涉及商业隐私,所以这些内容不是本栏目的重点。

    主结构

    由于主要是我一个人开发,而且目前也不涉及数据库操作,所以没有经典三层或是其它高大上的结构。

    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 Files7-Zip7z.exe"
    15 $7z="C:Program Files7-Zip7z.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='.SpiderXSpiderX.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.AdvActivatorSpiderX.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,但是对自觉性比较高的某人来说,可能还需要另外一处地方来记录问题。

  • 相关阅读:
    产品经理经常犯的错误李可按
    skills_hive
    skills_office
    skills_idea
    skills_linux
    skills_ubuntu
    skills_git
    skills_redis
    skills_centos
    problems_hive
  • 原文地址:https://www.cnblogs.com/godlessspirit/p/12687102.html
Copyright © 2011-2022 走看看