Skip to content

Instantly share code, notes, and snippets.

@MuhammadSulaiman001
Last active February 25, 2024 05:47
Show Gist options
  • Save MuhammadSulaiman001/1b8176c507321c168ccc31a2ef4f39f2 to your computer and use it in GitHub Desktop.
Save MuhammadSulaiman001/1b8176c507321c168ccc31a2ef4f39f2 to your computer and use it in GitHub Desktop.

.vcxproj setup (best practices)

  1. Project Properties -> General:

    • Top dropdowns = "All configurations" and "All platforms",
    • C++ Language Standard = C++ 20
    • Output and Temp Directories (default location is at .sln level)
      • Set Output Directory to $(ProjectDir)$(Platform)\$(Configuration)
      • Set Temp Directory to $(ProjectDir)$(Platform)\Temp-$(Configuration)
  2. Headers:

    • Project Properties -> C\C++ -> General -> Additional Include Directories = add relative path to where those header files are.
  3. Libs:

    • Project Properties -> Linker -> General -> Additional Library Directories = add a relative path to .lib files,
    • Project Properties -> Linker -> Input -> Additional Dependencies = add .lib names (separated by ;)
  4. Source Code:

    • Add C/C++ files to the project, then:
    • Solution Explorer -> Show Hidden Files -> Right click on the newly added source files -> Include In Project.
  5. DLLs:

  • Project Properties -> Build Events -> Post-Build-Event, you have two options:

    5.1. Trigger powershell to execute a .ps1 script that copies the dlls to output directory (recommended)

    • Example post build event that triggers .ps1 script that does the post-build setup (MAKE SURE PWSH added to PATH)
    pwsh -file .\automation\post-build.ps1 "$(ProjectDir.TrimEnd('\'))" "$(outputPath.TrimEnd('\'))"
    
    • Sample post-build.ps1 script (ex. resides in automation directory inside project folder)
    param([string]$projectDir, [string]$outputPath);
    
    # some logging
    Write-Host "ProjectDir = $projectDir"
    Write-Host "OutputPath = $outputPath"
    
    # 1. Copy dlls to output directory
    Write-Host "Copying dlls to output dir..."
    Copy-Item -Path "$projectDir\dlls\*" -Destination "$outputPath" -Force -Recurse # this\* will make the .dll files, not the folder.
    
    # 2. Copy resources to output directory
    Write-Host "Copying resources to output dir..."
    Copy-Item -Path "$projectDir\resources" -Destination "$outputPath" -Force -Recurse # copies resources folder
    
    Write-Host "DONE."
    

    5.2. Or: add xcopy command to copy .dll files to output directory

    • Example post build events to copy the needed files/folders to output directory
    REM copy res directory to output
    xcopy "$(ProjectDir)res" "$(OutputPath)res" /Y /I /E
    REM copy .dll files directory to output (todo test)
    xcopy "$(ProjectDir)dlls\*" "$(OutputPath)" /Y /I /E
    

    Take a look at this project as an example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment