Handmade Hero»Forums»Code
moz
3 posts
Visual Studio compile while debugging
I really liked the idea of having a loader program load the game code and pass the memory back into the freshly compiled DLL when it gets reloaded.

Currently I have one VS(2013) solution containing multiple projects, including a platform/loader program and the game code. However I'm unable to build a project while another is running in the same solution. A 'do you want to stop debugging' pop-up comes up. Perhaps I can force it to compile using msbuild or cl via command-line or maybe there a setting that I've overlooked. Has anyone got any ideas?
Mārtiņš Možeiko
2559 posts / 2 projects
Visual Studio compile while debugging
Yeah there is no other way.

You can set up external tool that will invoke "devenv /build dll_project.vcxproj" command to compile your solution. Or call msbuild instead of devenv.

People have done something similar here: https://hero.handmadedev.org/foru...you-set-up-vs-to-output-a-dll#872
moz
3 posts
Visual Studio compile while debugging
Edited by moz on
Thanks mmzozeiko that got me on the right track.

As with Casey on the stream there were issues with PDB files getting locked. HMH compiles using its build.bat with compiler and linker flags that I have very little knowledge on and don't feel like investing my time in at this time. So I wanted to keep things as simple as possible and try to let VS handle as much as possible. Yet it gave me this look telling me to stuff myself for wanting to define a custom PDB filename.

In HMH build.bat the PDB file name uses %random% to circumvent the PDB locking issue providing the name to CL.exe with the /PDB argument. However I am using MSBuild.exe to compile using the vsproj files. And MSBuild.exe wants to know nothing about any PDB filename, it will use the one defined in the project file and nothing else. Trying to add arguments in the project's linker command line settings was fruitless as %random% was not supported and as far as I know there are no VS macros to echo either dates or random numbers.

After some experimenting and banging my head against a wall I found out that you can still tell the linker to output a specific PDB filename by providing a props file that looks something like this.


1
2
3
4
5
6
7
8
    <?xml version="1.0" encoding="utf-8"?>    
    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
        <ItemDefinitionGroup>
            <Link>
                <ProgramDatabaseFile>..\Bin\Game_583510127.pdb</ProgramDatabaseFile>
            </Link>
        </ItemDefinitionGroup>
    </Project>


Using the same method as in the other thread I used an external tool hotkey to run the following batfile.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
call "C:\Program Files (x86)\Microsoft Visual Studio 13.0\VC\vcvarsall.bat"
type nul>Bin\compiling.tmp

REM We delete all not-in-use PDB's. This means if we compile multiple times we'll get a big list of PDBs which will be deleted next clean run we do.
del Bin\*.pdb
REM Create our simple PROPS file that MSBUILD takes with a unique PDB filename. 
call PropsBuilder.exe

REM I'm too dumb to get a relative path to work for the PROPS file.
call msbuild.exe /VERBOSITY:minimal Uluru.sln /target:Game /p:ForceImportBeforeCppTargets="D:\Development\Personal Projects\SVN-ed\Projects\Uluru\game_overrides.props";Platform=x86

del Bin\compiling.tmp

echo Compiling done.


Now there are two caveats. First is that I couldn't get the bat file to properly output that kind of XML without having to account for characters such as " and < >. It would mess up the commands and complain about unexpected characters, it's to be expected but because I wanted to see if it would work at all I created a small program (PropsBuilder.exe) that just generates the props file with a random number in the PDB filename. Another caveat, as stated in the bat file, is that PDBs start to pile up and only get removed the next time the old ones aren't locked. Minor gripe but I don't really care for now. On a side note, in my testing I made the Linker/Debugging/Generate Program Database File setting empty in the project file, if that does anything who knows? Oh and the absolute path makes me want to cry but hey, it's working now so I'm a happy camper.
Mārtiņš Možeiko
2559 posts / 2 projects
Visual Studio compile while debugging
You can set pdb filename in linker properties of Visual Studio Project (not solution, but project). No need to pass to msbuild anything.

From https://hero.handmadedev.org/foru...g-vs-instead-of-a-text-editor#825 topic:

You can put "$(ProjectName)-$([System.Guid]::NewGuid()).pdb" as pdb name. This will generate new guid every time linker is called.

Or you can put there something $(OutDir)$(TargetName)-$([System.DateTime]::Now.ToString("HH_mm_ss_fff")).pdb for shorter names.
moz
3 posts
Visual Studio compile while debugging
Well there you go. Awesome, I'll give that a whirl and it should clean things up nicely. I'm not even mad, in the end when you finally beat the system into submission it can be a liberating feeling. But strange how VS doesn't show or hint at those kind of commands in the macros section. And I learned today that google definitely isn't the end all for these kind of things. I hardly found anything useful there and had to grab bits from everywhere to get where it is now. Yet one search on the HMH forums would've saved me the trouble probably.

Thanks again.
Mārtiņš Možeiko
2559 posts / 2 projects
Visual Studio compile while debugging
Btw fyi to escape special command prompt characters like < and > you can use ^ symbol. ^ on command prompt is same thing as \ in C strings.

You can even use ^ to escape newline character and make multi-line commands:
1
2
echo Is 2 ^> 5 ^
???


Will display this:
1
Is 2 > 5 ???