Skip to content
FullStackGuru edited this page Jun 16, 2025 · 146 revisions

🚀 Work Daily Report

menu
Date Title
2025-06-16 🐞 Timestamp Handling Strategy
2025-06-16 🧠 WPF UI/UX Refinement
2025-06-16 🧠 Add retry mechanism with SERIALIZABLE isolation to UpdateDicRowsAsync
2025-06-13 🧠 Add SyncHelper with automatic and manual database sync functionality
2025-06-13 🥔 Refactor: separate helper classes into individual files
2025-06-13 🧠 Create a Shared Resource
2025-06-12 🚀 Improve performance by changing linear search O(N²) to use the dictionary’s key for O(1) lookup
2025-06-11 🐞 Solve overlapping beams or duplicated draws
2025-06-11 🐞 PostgreSQL Table Creation & LastModified Timestamp Handling
2025-06-10 🐞 Debug AddOrUpdateRecords for Bulk Upsert (Insert + Update) with Composite Key (Id, Spec)
2025-06-09 🧠 InsertRowsAsync the better version
2025-06-09 🚀 CreateTableAsync with Composite Primary Key and Index
2025-06-09 🐞 Debug PullUpdatesFromPostgres for Bulk insert
2025-06-07 🚀 High-Performance Bulk Insert from PostgreSQL to SQLite in C# using Npgsql's Binary COPY
2025-06-06 🚀 High-Performance Bulk Insert from SQLite to PostgreSQL in C# using Npgsql's Binary COPY
2025-06-05 🐞 Debug ID(int) Integer out of range in PostgreSQL
2025-06-04 🧠 Setup Connection of Azure PostgreSQL in VS Code
2025-06-04 🐞 Debug OnApplyAsync() to Fix async database save on app close to prevent freeze
2025-06-03 🐞 Prevent RadioButton_StatusChanged on Initialization
2025-06-03 🐞 Debug RadioButton_StatusChanged
2025-06-03 🚀 Refactor UpdateDatabaseEFAsync
2025-06-02 🐞 Convert String to TimeStamp
2025-06-02 🐞 Prevent SQLite Database Locked Errors by Setting journal_mode to WAL
2025-06-02 🧠 View Azure PostgreSQL Data in Azure Cloud Shell
2025-06-02 🧠 Connect to Azure Database for PostgreSQL flexible servers
2025-06-02 🐞 Fix .NET SDK Version and Stabilize CI Workflow for FwCAD
2025-05-29 🐞 SQLite->Postgresql->SQLite
2025-05-28 🔎 Synchronizing Edited Rows Between SQLite and PostgreSQL
2025-05-28 🧠 Pull and Push Database
2025-05-28 🧠 Drop All Tables PostgreSQL Schema
2025-05-28 🧠 Copy All Tables from SQLite to PostgreSQL
2025-05-28 🧠 Azure database services
2025-05-27 🧠 Command Prompt commands
2025-05-27 🧠 Install Azure Cosmos DB Emulator (Windows)
2025-05-22 🧠 Copy All Tables to SQLite DB
2025-05-22 🛠️ Git (list and clear stashed staged files)
2025-05-22 🧠 SQLite + Json free (KoukanBeam)
2025-05-21 🧠 Why Interface (to enable pre-set properties for generic type T )
2025-05-21 🧠 Delete SQLite DB with EF Core
2025-05-21 🧠 Update SQLite DB with EF Core
2025-05-20 🧠 Create a Generic OnEditDataGridCell Command Using ViewModel Type
2025-05-20 🧠 Create a Generic LoadData Command Using ViewModel Type
2025-05-20 🧠 Create a Generic Delete Command Using ViewModel Type
2025-05-20 🧠 Lambda Expression
2025-05-19 🧠 OptimizedSync to Sync Temp DB → Main DB in EF Core with Dynamic Model Type
2025-05-19 🧠 SQLite + EF Core Temp DB Handling (prevent file lock)
2025-05-16 🧠 EF Core Update with Values and Conditions
2025-05-16 🧠 Entity Framework Core (EF Core) Update Database
2025-05-16 🐞 Avoiding 'UNIQUE constraint failed' in EF Core: A Step-by-Step Guide with SQLite
2025-05-16 🧠 Entity Framework Core (EF Core) vs SQL query
2025-05-15 🧠 Create Temporary SqliteDB Table
2025-05-15 🧠 Auto Create the database at runtime (update-database)
2025-05-14 🐞 DataGrid RowHeight Reset Back Issue
2025-05-14 🧠 MVVM Properties GET SET
2025-05-14 🐞 Safely Access ItemsSource After Data Binding
2025-05-13 🎯 Canvas static elements defined in XAML get removed Solution
2025-05-12 🐞 Upload and Store Image Data as Byte Arrays in SQLite Using EF Core (with Size Limit Fix!)
2025-05-09 🐞 Fixing JSON Number-to-String Conversion Errors in ASP.NET Core
2025-05-09 🎯 Setup Generic CRUD operations
2025-05-08 🎯 Save JSON data into database using SignalR
2025-05-08 🎯 Create the FwCadServer ASP.NET Core Web API project with EF Core and SignalR
2025-05-08 🧠 Saving JSON data into SQLite database (custom reflection-based method)
2025-05-07 🧠 Azure Functions + Azure Web PubSub + SQLite with Azure Blob Storage (Local Architecture Simulation)
2025-05-07 🧠 Force cell edit to commit before calling method (DataGrid)
2025-05-02 🧠 Extract the label text (Regular Expression)
2025-05-02 🧠 async Task (Dispatcher.Yield)
2025-05-02 🎯 Set the Text of the Beam label TextBlock
2025-05-01 🧠 async Task
2025-04-30 🧠 XAML Binding to Conditional Visibility and Dynamic Text with Converters
2025-04-30 🎯 Simplifying Event Handling with RoutedEventArgs (🧠event-driven programming)
2025-04-28 🎯 ProgressRing
2025-04-28 🎯 Disable Entire Canvas to prevent user interaction during processing
2025-04-28 🧠 Await Async not necessary case
2025-04-28 🎯 Invoke Parent Method to Reload Data
2025-04-25 🎯 Temporarily clear space around a beam before resizing it (Edit Beam Width
2025-04-25 🎯 Move a particular child’s Canvas.Left position (Add new Beam)
2025-04-25 🐞🐞 File locking issue when building WPF apps
2025-04-24 🎯 WPF DataGrid Validation: LengthMin Must Be ≤ LengthMax (Dispatcher)
2025-04-24 🎯 Set IsReadOnlyProperty DataGridTextColumn
2025-04-24 🎯 await vs wait
2025-04-23 🎯 Refactor Code
2025-04-22 🌐 Dynamic Site with GitHub Pages and Actions
2025-04-22 🐞🐞 Re-register Explorer.exe
2025-04-21 🎯 Refactor SetComboBoxItems
2025-04-21 🎯 Get Canvas Properties
2025-04-21 🎯 Pass data list to other class
2025-04-21 🎯 Model add migration
2025-04-21 ✅ Auto or Manually Kill the Process / Task : taskkill /PID 27088 /F
2025-04-19 🎯 Dynamically Populating a ComboBox Item
2025-04-18 🎯 Dynamic Partition Markers Drawing on Canvas
2025-04-18 🌐 Web Server
2025-04-18 🌐 Send JSON from WPF to WebSocket and Insert into SQLite table
2025-04-18 🌐 Create SQLite Table with SQLite CLI
2025-04-17 Build Full Working .NET 6+ Web API + WebSocket Server
2025-04-17 Central Web API Architecture
2025-04-17 🔌 WPF App Startup: Asynchronous Database Connection for Fast & Smooth User Experience
2025-04-16 Running Actions-Runner on GitHub
2025-04-15 EF Core Bulk Insert/Update
2025-04-14 RelayCommand
2025-04-11 Displaying Title in ComboBox Dropdown while Binding Dim3 Value
2025-04-10 Dynamically setting the idPropertyName
2025-04-10 📐Importing CAD JSON Data into SQLite with Model Defaults
2025-04-09 📐Reading a JWW CAD File and Saving as JSON in a WPF Application
2025-04-08 GitHub Actions Self-Hosted Runner Hangs During Test Execution (SQLite Access)
2025-04-07 Using NUnit for WPF Tests in GitHub Actions
2025-04-04 Test Execution Still Failure in GitHub Actions
2025-04-03 Setup and run test on action-runner
2025-04-02 Solving the workflow setting for the C++ project
2025-04-01 GitHub Actions Workflow Automation and Deployment
2025-03-30 CI/CD with GitHub Actions: Setting Up Self-Hosted Runner for C# WPF Project
2025-03-28 Create the bat file to auto start the runner

✅ Reopen PowerShell as Administrator in the Same Folder:

Start-Process powershell -Verb runAs -ArgumentList "-NoExit", "-Command Set-Location -LiteralPath '$((Get-Location).Path)'"

🔍 What this does:

  • -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

Merge main into production and solve conflict

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"
setup-and-run-test-on-action-runner
🍓 **2025-04-03: Setup and run test on action-runner** 🔧🚀

🥔Fixing VCTargetsPath Error in Visual Studio

Issue Description

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 (\).

Why is VCTargetsPath Important in a WPF Project?

Even though WPF primarily uses C# and XAML, you might have C++/CLI (Common Language Infrastructure) components in your WPF project. This happens if:

  1. Your WPF project references a C++/CLI project (e.g., for performance reasons or legacy code).
  2. You are using a native C++ library with P/Invoke or interop (e.g., Open CASCADE in your case).
  3. 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.

Solution: Set VCTargetsPath Correctly

To fix this issue, ensure that VCTargetsPath is set correctly in the system environment variables.

Steps to Fix:

  1. Open Run (Win + R), type sysdm.cpl, and press Enter.
  2. Go to the Advanced tab and click on Environment Variables.
  3. Under System Variables, look for VCTargetsPath:
    • If it exists, edit it and ensure it is set to:
      C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\
      
      (Note the trailing \ at the end.)
    • If it doesn’t exist, create a new system variable with the above value.
  4. Click OK and restart your computer.

Additional Steps if the Issue Persists:

  • Delete the .vs, bin, and obj 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 to VCTargetsPath are correct.

Summary

  • Ensure VCTargetsPath ends with \.
  • Update the environment variable if necessary.
  • Clean and rebuild the project in Visual Studio.

🥔Run the workflow from localself-hosted

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 }}

If you got error of

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.

📌 Install Visual Studio Build Tools on Your Self-Hosted Runner to solve the above issues

Since you're using a self-hosted GitHub Actions runner, you need to install Visual Studio Build Tools manually on your runner machine.


🚀 Step-by-Step Installation

Follow these steps to install Visual Studio Build Tools, MFC, and MSBuild on your runner machine.

🔹 Step 1: Open PowerShell as Administrator

  1. On your runner machine, open PowerShell.
  2. Run it as Administrator.

🔹 Step 2: Install Chocolatey

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.


🔹 Step 3: Install Visual Studio Build Tools and Required Components

Run these one by one in PowerShell (as Admin):

1️⃣ Install Visual Studio Build Tools

choco install visualstudio2022buildtools --force --params "--add Microsoft.VisualStudio.Workload.VCTools --includeRecommended"

2️⃣ Install MFC Components

choco install visualstudio2022buildtools --force --params "--add Microsoft.VisualStudio.Component.VC.ATL --add Microsoft.VisualStudio.Component.VC.MFC --includeRecommended"

3️⃣ Install MSBuild Tools

choco install visualstudio2022buildtools --force --params "--add Microsoft.VisualStudio.Workload.MSBuildTools --includeRecommended"

💡 This will take a while! Let the installation complete.


🔹 Step 4: Restart the Runner Machine

After installation, restart your runner machine to apply changes.


🔹 Step 5: Verify Installation

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.)


🔹 Step 6: Restart Your GitHub Runner

Once everything is installed, restart your runner:

  1. Stop the runner
    Go to the folder where your runner is installed and run:

    ./svc.sh stop
  2. Start the runner

    ./run.sh

🔄 Summary

✅ Install Chocolatey
✅ Install Visual Studio Build Tools
✅ Install MFC and MSBuild
✅ Restart your machine and runner
✅ Verify installation with MSBuild and VCTools

🔹 Add MSBuild to the System PATH

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!

---
solving-the-workflow-setting-for-the-c-project
🍓 **2025-04-02: Solving the workflow setting for the C++ project** 🔧🚀

Issue

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.

Workflow Configuration

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 }}

🔍 Step 1: Verify Your Installed Components

  1. Open Visual Studio Installer

    • Press Win + S, search for Visual Studio Installer, and open it.
    • Click Modify on Visual Studio 2022 Community.
  2. 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.


🔍 Step 2: Manually Check Installed Files

  1. Open File Explorer and go to:

    C:\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\
    

    You should see v150, v160, and v170, but not v170Platforms.

  2. 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!


🔧 Step 3: Manually Copy Missing Files

If v170Platforms is still missing after reinstalling the components:

1️⃣ Copy from an Existing Version

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.

2️⃣ Reinstall VS Build Tools (Last Resort)

If you do not have v150Platforms or v160Platforms, reinstall VS Build Tools:

  1. Download Visual Studio Build Tools from:
    👉 https://visualstudio.microsoft.com/visual-cpp-build-tools/
  2. Run the installer, select C++ Desktop Development, and install all required components.
  3. Restart your computer and check if v170Platforms appears.

📢 Final Steps

After ensuring v170Platforms exists, run:

msbuild /t:clean
msbuild JwwControl.vcxproj

ci-cd-with-github-actions-setting-up-self-hosted-runner-for-c-wpf-project
🍓 2025-03-30: CI/CD with GitHub Actions: Setting Up Self-Hosted Runner for C# WPF Project 🔧🚀

Overview

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


1. Introduction to CI/CD and GitHub Actions 🎉

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.

📖 Read More


2. Setting Up a Self-Hosted Runner 🖥️

A self-hosted runner allows GitHub Actions workflows to execute on your own machine.

📌 Steps:

1️⃣ Navigate to your GitHub repository → SettingsActionsRunners
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!


3. GitHub Actions Workflow Configuration ⚙️

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

github-actions-workflow-automation-and-deployment
🍓 2025-04-01: GitHub Actions Workflow Automation and Deployment 🚀

Automating the CI/CD Pipeline

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


Deploying the Application 🚀

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!

📖 Read More


🎯 Conclusion

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! 🚀


bat-auto-runner
🍓 2025-03-28: Automating Service Startup on Windows Boot: Creating `start_services.bat` 🚀

📌 Introduction

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.

🛠️ Prerequisites

Before proceeding, ensure you have the following installed and configured:

  1. Java (for Jenkins)
  2. Jenkins (jenkins.war should be placed in a known directory)
  3. GitHub Actions Runner (already configured in C:\Projects\actions-runner)
  4. ngrok (installed and accessible via command line)
  5. Git (configured with SSH or HTTPS authentication)

📝 Creating the start_services.bat Script

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

🔥 Understanding the Script

Here’s a breakdown of what this script does:

1. Start Jenkins

  • Runs Jenkins in the background on port 8080.
  • Uses start /B to keep it running without opening a separate window.

2. Ensure GitHub Actions Runner is Running

  • Checks if Runner.Listener.exe is running.
  • If not, navigates to C:\Projects\actions-runner and starts it.

3. Start ngrok & Capture Public URL

  • 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.

4. Update GitHub Actions Workflow with the New ngrok URL

  • Updates potato.yml in the GitHub repository.
  • Uses PowerShell to replace the old ngrok URL with the new one.

5. Synchronize with GitHub Repository

  • Pulls the latest changes from origin/main.
  • Handles merge conflicts if any.
  • Commits and pushes changes automatically.

🚀 Automating the Script Execution on Windows Startup

To make this script run every time Windows starts, follow these steps:

Step 1: Create a Shortcut

  1. Right-click on start_services.bat and select Create Shortcut.
  2. Rename the shortcut to something like Start Services.

Step 2: Add to Startup Folder

  1. Press Win + R, type shell:startup, and hit Enter.
  2. Copy the shortcut into the opened folder.

Now, every time Windows starts, your script will execute automatically! 🎉


Clone this wiki locally