-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Start-Process powershell -Verb runAs -ArgumentList "-NoExit", "-Command Set-Location -LiteralPath '$((Get-Location).Path)'"
-
-Verb runAs
— runs PowerShell as Administrator -
-NoExit
— keeps the new window open -
-Command Set-Location -LiteralPath ...
— tells the new PowerShell window to change directory to your current one
git checkout production
git merge origin/main
# You'll see conflict markers <<<<<< HEAD etc. in the file
# Manually fix the conflicts in .github/workflows/main.yml
git add .github/workflows/main.yml
git commit -m "Resolve workflow conflict"
🍓 **2025-04-03: Setup and run test on action-runner** 🔧🚀
If you encounter the following error when building your project in Visual Studio:
The imported project "C:\Microsoft\VC\v170\Microsoft.Cpp.Default.props" was not found.
Confirm that the expression in the Import declaration "$(VCTargetsPath)\Microsoft.Cpp.Default.props",
which evaluated to "C:\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.Cpp.Default.props",
is correct, and that the file exists on disk.
This typically happens because the VCTargetsPath
environment variable is incorrectly set or missing a trailing backslash (\
).
Even though WPF primarily uses C# and XAML, you might have C++/CLI (Common Language Infrastructure) components in your WPF project. This happens if:
- Your WPF project references a C++/CLI project (e.g., for performance reasons or legacy code).
- You are using a native C++ library with P/Invoke or interop (e.g., Open CASCADE in your case).
- Your solution includes both C# and C++ projects, such as a mixed-language setup.
When you build your project, MSBuild relies on VCTargetsPath
to locate these C++ build definitions. If the path is incorrect or missing, Visual Studio cannot find the necessary build scripts, leading to errors like:
The imported project "C:\Microsoft\VC\v170\Microsoft.Cpp.Default.props" was not found.
To fix this issue, ensure that VCTargetsPath
is set correctly in the system environment variables.
- Open Run (
Win + R
), typesysdm.cpl
, and press Enter. - Go to the Advanced tab and click on Environment Variables.
- Under System Variables, look for
VCTargetsPath
:- If it exists, edit it and ensure it is set to:
(Note the trailing
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\
\
at the end.) - If it doesn’t exist, create a new system variable with the above value.
- If it exists, edit it and ensure it is set to:
- Click OK and restart your computer.
- Delete the
.vs
,bin
, andobj
folders in your project directory. - Open Visual Studio and Rebuild Solution.
- If the error still occurs, manually edit
JwwControl.vcxproj
and ensure that all references toVCTargetsPath
are correct.
- Ensure
VCTargetsPath
ends with\
. - Update the environment variable if necessary.
- Clean and rebuild the project in Visual Studio.
name: Potato Workflow
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
# ✅ # Use Windows since you're working with Visual Studio projects
runs-on: [self-hosted, windows] # Ensure this is set to your self-hosted runner.
steps:
- name: Checkout code
uses: actions/checkout@v2
# Cache Visual Studio Build Tools installer
- name: Cache Visual Studio Build Tools
uses: actions/cache@v3
with:
path: C:\path\to\visualstudio_installer_cache
key: ${{ runner.os }}-vs_installer-${{ hashFiles('**/vs_installer.exe') }}
# Initialize Visual Studio Environment Variables
- name: Initialize Visual Studio Environment Variables
run: |
& "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat"
- name: Set VCTargetsPath
run: |
echo "VCTargetsPath=C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8
# Clean the solution (optional)
- name: Clean Solution
shell: cmd
run: |
CALL "C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe" /t:Clean Fw.sln
# ✅ Restore dependencies
- name: Restore .NET dependencies
run: dotnet restore
# Build solution using MSBuild (required for C++ projects) ✖
#- name: Build solution using MSBuild
# run: |
# msbuild D:\a\FwCAD\FwCAD\Fw.sln /p:Configuration=Release
# ✅ Restore dependencies using MSBuild (No installation needed)
#- name: Restore dependencies (MSBuild)
# run: |
# & "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\MSBuild.exe" /t:restore /p:Configuration=Release Fw.sln
# shell: pwsh
# ✅ Build the project using preinstalled MSBuild
#- name: Build the project
# run: |
# & "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\MSBuild.exe" /p:Configuration=Release Fw.sln
# shell: pwsh
# Build the solution ✖
#- name: Build solution
# run: dotnet build
- name: Initialize Visual Studio Environment Variables
run: |
call "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat"
shell: cmd
- name: Build Solution
run: |
"C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe" /p:Configuration=Release Fw.sln
shell: cmd
#- name: Build with MSBuild
# run: |
# "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\MSBuild\\Current\\Bin\\MSBuild.exe" FwCAD.sln /p:VCTargetsPath="C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\MSBuild\\Microsoft\\VC\\v170\\"
# shell: cmd # Use cmd for MSBuild command
# ✅ Run tests (if applicable)
- name: Run tests
run: dotnet test
# Set up Git credentials
- name: Set up Git credentials
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com"
# Fetch and checkout production branch
- name: Fetch and checkout production branch
run: |
git fetch origin
git checkout production
# Merge main into production
- name: Merge main into production
run: |
git pull origin production
# Push changes to production
- name: Push changes to production
run: |
git push origin production
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Run dotnet test
復元対象のプロジェクトを決定しています...
復元対象のすべてのプロジェクトは最新です。
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppBuild.targets(515,5): warning MSB8003: VCToolsInstallDir プロパティが定義されていません。一部のビルド ツールが見つからない可能性があります。 [C:\Projects\actions-runner\potato_work\FwCAD\FwCAD\OCControl\OCControl.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppBuild.targets(500,5): error MSB8041: このプロジェクトには、MFC のライブラリが必要です。使用されているツールセットとアーキテクチャについては、Visual Studio インストーラー (個々のコンポーネント タブ) からインストールします。 [C:\Projects\actions-runner\potato_work\FwCAD\FwCAD\JwwControl\JwwControl.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(203,5): error MSB4018: "GetOutOfDateItems" タスクが予期せずに失敗しました。 [C:\Projects\actions-runner\potato_work\FwCAD\FwCAD\OCControl\OCControl.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(203,5): error MSB4018: System.TypeLoadException: Could not load type 'Microsoft.Build.Utilities.CanonicalTrackedOutputFiles' from assembly 'Microsoft.Build.Utilities.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. [C:\Projects\actions-runner\potato_work\FwCAD\FwCAD\OCControl\OCControl.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(203,5): error MSB4018: at Microsoft.Build.CPPTasks.GetOutOfDateItems.Execute() [C:\Projects\actions-runner\potato_work\FwCAD\FwCAD\OCControl\OCControl.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(203,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Execute() [C:\Projects\actions-runner\potato_work\FwCAD\FwCAD\OCControl\OCControl.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(203,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(TaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [C:\Projects\actions-runner\potato_work\FwCAD\FwCAD\OCControl\OCControl.vcxproj]
Error: Process completed with exit code 1.
Since you're using a self-hosted GitHub Actions runner, you need to install Visual Studio Build Tools manually on your runner machine.
Follow these steps to install Visual Studio Build Tools, MFC, and MSBuild on your runner machine.
- On your runner machine, open PowerShell.
- Run it as Administrator.
If Chocolatey is not installed, install it with:
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
After installation, restart PowerShell.
Run these one by one in PowerShell (as Admin):
choco install visualstudio2022buildtools --force --params "--add Microsoft.VisualStudio.Workload.VCTools --includeRecommended"
choco install visualstudio2022buildtools --force --params "--add Microsoft.VisualStudio.Component.VC.ATL --add Microsoft.VisualStudio.Component.VC.MFC --includeRecommended"
choco install visualstudio2022buildtools --force --params "--add Microsoft.VisualStudio.Workload.MSBuildTools --includeRecommended"
💡 This will take a while! Let the installation complete.
After installation, restart your runner machine to apply changes.
Check if MSBuild and VC++ Tools are installed:
1️⃣ Check MSBuild Path
Get-Command msbuild
If installed, it should return something like:
CommandType Name Version Source
----------- ---- ------- ------
Application msbuild.exe 17.4.2 C:\Program Files\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\MSBuild.exe
2️⃣ Check VCTools Installation
$env:VCToolsInstallDir
If the output is empty, set it manually:
[System.Environment]::SetEnvironmentVariable("VCToolsInstallDir", "C:\Program Files\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.36.32532", [System.EnvironmentVariableTarget]::Machine)
(Change 14.36.32532
to your installed version.)
Once everything is installed, restart your runner:
-
Stop the runner
Go to the folder where your runner is installed and run:./svc.sh stop
-
Start the runner
./run.sh
✅ Install Chocolatey
✅ Install Visual Studio Build Tools
✅ Install MFC and MSBuild
✅ Restart your machine and runner
✅ Verify installation with MSBuild and VCTools
Since the msbuild
command is not recognized, we need to add it to the system PATH.
1️⃣ Run this command in PowerShell (Administrator mode):
[System.Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin", [System.EnvironmentVariableTarget]::Machine)
2️⃣ Restart PowerShell and GitHub Runner.
3️⃣ Verify MSBuild by running:
msbuild -version
After this, rerun your GitHub Actions workflow 🚀 Let me know if you get any errors!
🍓 **2025-04-02: Solving the workflow setting for the C++ project** 🔧🚀
The following workflow still encounters an error:
The error is caused by missing Visual Studio C++ build components, specifically the Microsoft.Cpp.Default.props file. Your workflow attempts to install Visual Studio Build Tools using Chocolatey but does not correctly configure the environment to use the installed tools.
name: Potato Workflow
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
# ✅ # Use Windows since you're working with Visual Studio projects
runs-on: windows-latest
strategy:
matrix:
dotnet-version: [8.0]
steps:
- name: Checkout code
uses: actions/checkout@v2
# ✅ Set up .NET SDK (No need for VS installation)
- name: Set up .NET SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ matrix.dotnet-version }}
# Install Visual Studio Build Tools
- name: Install Visual Studio Build Tools
run: |
choco install visualstudio2022buildtools --package-parameters "--add Microsoft.VisualStudio.Workload.VC --includeRecommended"
choco install visualstudio2022buildtools --package-parameters "--add Microsoft.VisualStudio.Workload.MSBuildTools --includeRecommended"
# Initialize Visual Studio Environment Variables
- name: Initialize Visual Studio Environment Variables
run: |
& "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\VsDevCmd.bat"
# Clean the solution (optional)
- name: Clean MSBuild Cache
run: |
& "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\MSBuild.exe" /t:Clean Fw.sln
shell: pwsh
# ✅ Restore dependencies
- name: Restore .NET dependencies
run: dotnet restore
# Build solution using MSBuild (required for C++ projects) ✖
#- name: Build solution using MSBuild
# run: |
# msbuild D:\a\FwCAD\FwCAD\Fw.sln /p:Configuration=Release
# ✅ Restore dependencies using MSBuild (No installation needed)
- name: Restore dependencies (MSBuild)
run: |
& "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\MSBuild.exe" /t:restore /p:Configuration=Release Fw.sln
shell: pwsh
# ✅ Build the project using preinstalled MSBuild
- name: Build the project
run: |
& "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\MSBuild.exe" /p:Configuration=Release Fw.sln
shell: pwsh
# Build the solution ✖
#- name: Build solution
# run: dotnet build
# ✅ Run tests (if applicable)
- name: Run tests
run: dotnet test
# Set up Git credentials
- name: Set up Git credentials
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com"
# Fetch and checkout production branch
- name: Fetch and checkout production branch
run: |
git fetch origin
git checkout production
# Merge main into production
- name: Merge main into production
run: |
git pull origin production
# Push changes to production
- name: Push changes to production
run: |
git push origin production
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-
Open Visual Studio Installer
- Press
Win + S
, search for Visual Studio Installer, and open it. - Click Modify on Visual Studio 2022 Community.
- Press
-
Ensure the Following Are Installed:
In the Workloads tab:
✅Desktop development with C++
(if not checked, enable it).In the Individual Components tab, check the following under “Compilers, build tools, and runtimes”:
- ✅ MSVC v143 - VS 2022 C++ x64/x86 build tools
- ✅ Windows 10 SDK (latest installed)
- ✅ Windows 11 SDK (latest installed)
- ✅ C++ CMake tools for Windows
- ✅ C++ ATL for v143
- ✅ C++ MFC for v143
- ✅ C++ CMake tools for Windows
📌 Make sure these are installed before proceeding. Click Modify to install missing components.
-
Open File Explorer and go to:
C:\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\
You should see
v150
,v160
, andv170
, but notv170Platforms
. -
Check inside the
v170
folder:C:\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\
- Do you see
Microsoft.Cpp.Default.props
? - Do you see
BuildCustomizations
?
📌 Let me know what files exist there!
- Do you see
If v170Platforms
is still missing after reinstalling the components:
Check if v160Platforms
or v150Platforms
exist:
C:\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v160Platforms\
C:\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v150Platforms\
If either exists, copy the entire folder and rename it to v170Platforms
.
If you do not have v150Platforms
or v160Platforms
, reinstall VS Build Tools:
-
Download Visual Studio Build Tools from:
👉 https://visualstudio.microsoft.com/visual-cpp-build-tools/ - Run the installer, select C++ Desktop Development, and install all required components.
-
Restart your computer and check if
v170Platforms
appears.
After ensuring v170Platforms
exists, run:
msbuild /t:clean
msbuild JwwControl.vcxproj
🍓 2025-03-30: CI/CD with GitHub Actions: Setting Up Self-Hosted Runner for C# WPF Project 🔧🚀
This guide covers implementing CI/CD using GitHub Actions for a C# WPF project. We will:
✅ Set up a self-hosted runner
✅ Modify GitHub Actions workflows
✅ Create unit tests
✅ Implement deployment strategies
CI/CD is an essential practice that enhances software development efficiency.
💡 Continuous Integration (CI): Automatically tests each code change to prevent bugs.
💡 Continuous Deployment (CD): Deploys changes to production or a testing environment once tests pass.
A self-hosted runner allows GitHub Actions workflows to execute on your own machine.
1️⃣ Navigate to your GitHub repository → Settings → Actions → Runners
2️⃣ Click New self-hosted runner and follow the installation steps
3️⃣ Run the setup script and start the runner
./config.sh --url https://github.com/your-repo --token YOUR_ACCESS_TOKEN
./run.sh
🚀 Your self-hosted runner is now ready to execute workflows!
Create a workflow YAML file for building and testing your WPF project.
📄 .github/workflows/ci.yml
name: Build and Test WPF App
on:
push:
branches:
- main
pull_request:
jobs:
build:
runs-on: self-hosted
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0.x'
- name: Restore Dependencies
run: dotnet restore
- name: Build Solution
run: dotnet build --configuration Release --no-restore
- name: Run Tests
run: dotnet test --no-restore --verbosity normal
🍓 2025-04-01: GitHub Actions Workflow Automation and Deployment 🚀
On day two, we improved the GitHub Actions workflow for our C# WPF project.
✅ Setup .NET 8.0 SDK
✅ Handle dependencies
✅ Build with MSBuild
✅ Run unit tests
✅ Deploy to production
Modify the workflow to automatically publish the application.
📄 .github/workflows/deploy.yml
name: Deploy WPF App
on:
push:
branches:
- main
jobs:
deploy:
runs-on: self-hosted
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0.x'
- name: Publish Application
run: dotnet publish -c Release -o ./publish
- name: Deploy to Server
run: |
scp -r ./publish user@your-server:/var/www/wpf-app
🚀 Your application will automatically deploy when changes are pushed to main
!
By following these steps, we've successfully:
✅ Configured a self-hosted runner
✅ Set up GitHub Actions workflows
✅ Implemented unit testing
✅ Automated deployment
🔗 Next Steps: Optimize CI/CD pipelines, add error logging, and refine deployment strategies.
📢 Need help? Open an issue or contribute to this repository! 🚀
🍓 2025-03-28: Automating Service Startup on Windows Boot: Creating `start_services.bat` 🚀
Managing multiple services manually every time you start your Windows system can be tedious. This tutorial will guide you through creating a batch script (start_services.bat
) that automates the startup of Jenkins, GitHub Actions Runner, ngrok, and Git operations.
By the end of this tutorial, your system will automatically:
- Start Jenkins in the background.
- Ensure GitHub Actions Runner is running.
- Start ngrok and update the workflow with the new public URL.
- Pull the latest code from your Git repository and push any necessary changes.
Before proceeding, ensure you have the following installed and configured:
- Java (for Jenkins)
-
Jenkins (
jenkins.war
should be placed in a known directory) -
GitHub Actions Runner (already configured in
C:\Projects\actions-runner
) - ngrok (installed and accessible via command line)
- Git (configured with SSH or HTTPS authentication)
Create a new file named start_services.bat
and paste the following script:
@echo off
echo Starting Jenkins...
:: Start Jenkins in the background
start /B java -jar jenkins.war --httpPort=8080 --httpListenAddress=0.0.0.0
echo Jenkins started.
:: Wait a few seconds for Jenkins to start
timeout /t 5
:: Check if Actions Runner is running
tasklist | find /i "Runner.Listener.exe" > nul
if %errorlevel% neq 0 (
echo GitHub Actions Runner is not running. Starting now...
cd /d "C:\Projects\actions-runner"
start /B run.cmd
) else (
echo GitHub Actions Runner is already running.
)
:: Start ngrok and capture the public URL
echo Starting ngrok...
start /B ngrok http 8080 > nul 2>&1
:: Wait for ngrok to initialize
timeout /t 5
:: Fetch the ngrok URL using PowerShell
for /f "delims=" %%A in ('powershell -Command "(Invoke-RestMethod -Uri 'http://127.0.0.1:4040/api/tunnels').tunnels[0].public_url"') do set NGROK_URL=%%A
:: Trim the quotation marks from the URL
set NGROK_URL=%NGROK_URL:"=%
echo ngrok URL: %NGROK_URL%
:: Update the ngrok URL in `potato.yml`
powershell -Command "(Get-Content C:\Projects\ConvertImageToBase64\.github\workflows\potato.yml) -replace 'https://.*?\.ngrok-free\.app', '%NGROK_URL%' | Set-Content C:\Projects\ConvertImageToBase64\.github\workflows\potato.yml"
:: Pull the latest changes from origin and merge with local changes
echo Pulling latest changes from origin main...
cd /d C:\Projects\ConvertImageToBase64
git fetch origin
git pull origin main
:: Check if there was an error while pulling (e.g., merge conflicts)
if %errorlevel% neq 0 (
echo There was an error while pulling from the remote repository. Please resolve any conflicts and try again.
pause
exit /b
)
:: Check if a merge is in progress (MERGE_HEAD exists)
if exist .git\MERGE_HEAD (
echo Merge is in progress. Committing the merge...
git commit --no-edit
)
:: Check for uncommitted changes (before merge or after conflict resolution)
git diff --exit-code > nul
if %errorlevel% neq 0 (
echo Uncommitted changes detected. Committing changes...
git add .
git commit -m "Auto-commit changes"
)
:: Push the merged changes to GitHub
git push origin main
echo All services are running. The GitHub Actions workflow has been updated.
pause
Here’s a breakdown of what this script does:
- Runs Jenkins in the background on port 8080.
- Uses
start /B
to keep it running without opening a separate window.
- Checks if
Runner.Listener.exe
is running. - If not, navigates to
C:\Projects\actions-runner
and starts it.
- Runs ngrok in the background.
- Waits for initialization and fetches the ngrok public URL.
- Uses PowerShell to parse the JSON response and extract the URL.
- Updates
potato.yml
in the GitHub repository. - Uses PowerShell to replace the old ngrok URL with the new one.
- Pulls the latest changes from
origin/main
. - Handles merge conflicts if any.
- Commits and pushes changes automatically.
To make this script run every time Windows starts, follow these steps:
- Right-click on
start_services.bat
and select Create Shortcut. - Rename the shortcut to something like Start Services.
- Press
Win + R
, typeshell:startup
, and hit Enter. - Copy the shortcut into the opened folder.
Now, every time Windows starts, your script will execute automatically! 🎉