From 3a4d82a8071bbc50d377c60ea5c1fc4c28323ab3 Mon Sep 17 00:00:00 2001 From: mingkuang Date: Wed, 19 Apr 2023 21:09:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0Action=20CI=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/Build.yml | 111 ++++++++++++++++++++++++++++++++++++ README.md | 36 ++++++++++-- 2 files changed, 141 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/Build.yml diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml new file mode 100644 index 0000000..8e704d5 --- /dev/null +++ b/.github/workflows/Build.yml @@ -0,0 +1,111 @@ +name: Build + +on: [push, pull_request] + +jobs: + Build: + runs-on: windows-latest + + steps: + - uses: actions/checkout@v2 + + - name: 初始化 + working-directory: ${{github.workspace}} + run: | + $ProgramFiles = ${env:ProgramFiles(x86)} + + if (-not $ProgramFiles) + { + $ProgramFiles = $env:ProgramFiles + } + + $BuiltInVsWhereExe = "$ProgramFiles\Microsoft Visual Studio\Installer\vswhere.exe" + + if (-not (Test-Path $BuiltInVsWhereExe)) + { + throw "找不到vswhere.exe!" + } + + Write-Output $BuiltInVsWhereExe + + $LatestVisualStudioRoot = & $BuiltInVsWhereExe -latest -prerelease -property installationPath + + if (-not (Test-Path $LatestVisualStudioRoot)) + { + throw "找不到 VisualStudioRoot!" + } + + echo "LatestVisualStudioRoot=$LatestVisualStudioRoot" >> $env:GITHUB_ENV + + $MSBuildBinPath="$LatestVisualStudioRoot\MSBuild\Current\Bin" + + if (-not (Test-Path $MSBuildBinPath)) + { + $installationVersion = & $BuiltInVsWhereExe -latest -prerelease -property installationVersion + $majorVersion = "$installationVersion".Split('.')[0] + + $MSBuildBinPath="$LatestVisualStudioRoot\MSBuild\$majorVersion.0\Bin" + } + + if (-not (Test-Path $MSBuildBinPath)) + { + throw "找不到 MSBuildBinPath!" + } + + echo "MSBuildBinPath=$MSBuildBinPath" >> $env:GITHUB_ENV + + if($env:GITHUB_REF.StartsWith("refs/tags/v", "CurrentCultureIgnoreCase")) + { + $BuildVersion = $env:GITHUB_REF.Remove(0, 11); + echo "BuildVersion=$BuildVersion" >> $env:GITHUB_ENV + } + + - name: 执行编译 + working-directory: ${{github.workspace}} + shell: pwsh + run: | + # MSBuild 目录更新到 Path + $Env:Path="${{env.MSBuildBinPath}};${{env.LatestVisualStudioRoot}}\Common7\IDE\CommonExtensions\Microsoft\TestWindow;" + $Env:Path + + # 编译项目 + &msbuild Build.proj + if($lastexitcode -ne 0) + { + throw "编译失败!退出代码:$lastexitcode" + } + + - name: 文件打包 + working-directory: ${{github.workspace}} + shell: cmd + run: | + :: 打包Release + pushd Release + 7z a -tzip MSBuildCppCrossToolset-${{env.BuildVersion}}-Binary.zip VCTargets + if %ERRORLEVEL% NEQ 0 exit /B %ERRORLEVEL% + popd + 7z u -tzip Release\MSBuildCppCrossToolset-${{env.BuildVersion}}-Binary.zip LICENSE.txt README.md + + if %ERRORLEVEL% NEQ 0 exit /B %ERRORLEVEL% + + - uses: actions/upload-artifact@v2 + with: + path: | + Release/*.zip + + # 失败时我们收集一些信息,用于诊断 + - uses: actions/upload-artifact@v2 + if: failure() + with: + name: ErrorLog + path: | + Release/**/*.* + + - uses: xresloader/upload-to-github-release@v1 + if: contains(github.ref, 'tags/') + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + file: "Release/MSBuildCppCrossToolset-*.zip" + overwrite: true + tags: true + draft: false diff --git a/README.md b/README.md index 8975461..b60875a 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,22 @@ -# MSBuildCppCrossToolset +# MSBuildCppCrossToolset - LinuxMacOSбvcxproj +[![license](https://img.shields.io/github/license/Chuyu-Team/MSBuildCppCrossToolset)](https://github.com/Chuyu-Team/MSBuildCppCrossToolset/blob/master/LICENSE) +![downloads](https://img.shields.io/github/downloads/Chuyu-Team/MSBuildCppCrossToolset/total) +[![contributors](https://img.shields.io/github/contributors-anon/Chuyu-Team/MSBuildCppCrossToolset)](https://github.com/Chuyu-Team/MSBuildCppCrossToolset/graphs/contributors) +[![release](https://img.shields.io/github/v/release/Chuyu-Team/MSBuildCppCrossToolset?include_prereleases)](https://github.com/Chuyu-Team/MSBuildCppCrossToolset/releases) +[![Build](https://github.com/Chuyu-Team/MSBuildCppCrossToolset/actions/workflows/Build.yml/badge.svg)](https://github.com/Chuyu-Team/MSBuildCppCrossToolset/actions/workflows/Build.yml) + ҪʾVCTargetsеļ `Microsoft Visual Studio\?\?\MSBuild\Microsoft\VC` ȡMicrosoftӵȨ ҪʾĿδ깤 -Ŀ΢VCTargets޸ģΪMSBuildʵ˿ƽ̨vcxproj +Ŀ΢VCTargets޸ģΪMSBuildʵ˿ƽ̨vcxprojVSø߶ȳͳһĿһһӳ䡣 + +> ٸӣȫŻFullѡ΢ʱӳΪ `-Ox`ʹGCCʱӳΪ`-O3` δƻ * [ ] 벻Ч⡣ * [ ] ŻЧʡ +* [ ] Ԫԡ # 1. ## 1.1. ݵIJϵͳ @@ -33,19 +42,21 @@ * x86 # 2. ʹ÷ʽ -# 2.1. װ .NET +# 2.1. װ .NET SDK صַhttps://dotnet.microsoft.com/zh-cn/download -> Ŀǰʹõ .NET 6.0Ϊdz֧֣Ҳȷװ 7.0 ǷҵĽű +> ѡ .NET 6.0߸߰汾 ## 2.2. MSBuildCppCrossToolset - MSBuildCppCrossToolset ص `/home/john/Desktop/VCTargets`ִ +ȣǴ[Release](https://github.com/Chuyu-Team/MSBuildCppCrossToolset/releases)MSBuildCppCrossToolsetѹ + +սѹĿ¼`/home/john/Desktop/VCTargets`ִ ``` export VCTargetsPath=/home/john/Desktop/VCTargets/v170/ ``` -ǽʱVCTargetsPathVCTargetsPath17Ҫ־ã޸ϵͳá +ʱ`VCTargetsPath`Ҫ־ã޸ϵͳá ## 2.3. vcxprojĿ Ŀλã `/home/john/Desktop/ConsoleApplication2/ConsoleApplication2.vcxproj`ұ Release x86ô @@ -55,3 +66,16 @@ dotnet msbuild '/home/john/Desktop/ConsoleApplication2/ConsoleApplication2.vcxpr ``` > ܰʾ`PlatformToolset` 1.2. ݵıСжӦƽ̨߼ѡ񣬱˵GCC`YY_Cross_GCC_1_0` + +# 3. ôԼ MSBuildCppCrossToolset +> ܰʾͨûα MSBuildCppCrossToolsetֻҪReleaseؼɡ + +ע⣺MSBuildCppCrossToolsetҪװ`.NET 6.0 SDK` + +MSBuildCppCrossToolsetĿԴ: `D:\MSBuildCppCrossToolset` +``` +# Ҳʹ dotnet CLI +msbuild D:\MSBuildCppCrossToolset\Build.proj +``` + +ִгɹReleaseĿ¼