Modifying project files in Visual Studio during pre-build

So it turns out that Visual Studio uses the application’s cache if a file is open at build time instead of loading the file off disk…ok so this is good, when you want to save memory and speed up the build process. BUT when you are editing a source file that is being created/modified during the Pre-Build step, then you are in a little bit of trouble.

After some digging, it turns out that it’s a known process and in visual studio 2008 (at least) an additional option is not going to be added. So how do we get around this?

Add the highlighted line to your projects build settings and it will force the applications to load the file from disk and not from its cache. It didn’t take me too long to find this information out, but it’s good to know if you get in a position that you need to do this.

<UseHostCompilerIfAvailable>false</UseHostCompilerIfAvailable>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'PCRelease|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseHostCompilerIfAvailable>false</UseHostCompilerIfAvailable>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>

Source:

Original Microsoft Feedback Post