Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Salvatore Previti's host compiler caching workaround #40

Open
GoogleCodeExporter opened this issue Jun 1, 2015 · 1 comment

Comments

@GoogleCodeExporter
Copy link

// <summary>
    /// Author: Salvatore Previti - 08-April-2009.
    /// 
    /// Visual studio host compiler keeps a cache of files during the MSBuild step, so they are not readed from disk.
    /// This is ok for performance and intellisense, right, but this introduces also some subtle bug!
    /// 
    /// See forum thread "Generated Code Not Building - VS Caching Problem?" at http://social.technet.microsoft.com/Forums/en-US/msbuild/thread/14bb304d-d8e6-4227-bc2b-e2e6d4f979be?ppud=4 for more informations.
    /// This task contains a simple but effective work around to this caching bug :)
    /// 
    /// How it works:
    /// 
    /// Visual studio keeps MSBuild Tasks dll loaded also between different compilations in the same appdomain where MSBuild is executed.
    /// Due to this fact, we can keep some states (static variables) between different compilations during the same development session.
    /// This class, infact, uses a static synclocked dictionary to keep states between different compilations.
    /// Each time static function UpdateFileUsageCount is called with the same prefix and with the same filename (case insensitive), the resulting value is incremented.
    /// 
    /// There is another "feature" (bug?) in visual studio cache mechanism... &lt;Compile Include="c:\test.cs"&gt and &lt;Compile Include="c:\test.cs "&gt
    /// are considered different files, so, they are cached as two different files (look the space character in "test.cs " in the second Compile tag).
    /// MSBuild and all filesystems, instead, treat both files as the same :)
    /// 
    /// So the solution! Each time we generate a file, we use a different number of spaces using our in-ram dictionary.
    /// The static function that does this is UpdateSpaces.
    /// During tests, a single space seems sufficient, but to be safe, I used MaxSpaces constant to use more than one space.
    /// 
    /// This system has some drawback, though:
    ///     1) You need to use this Task, so, you have to include a DLL and add some tags to your MSBuild project.
    ///     2) This should works for full pathed filenames.
    ///     3) Not garbage collector friendly - some objects (internal static dictionary and some Visual Studio cached files) will never be released and there is no way to release them.
    ///        This is a small amount of RAM, though, and should not be a problem during development.
    ///        During command-line MSBuild this problem can be ignored.
    /// </summary>

Original issue reported on code.google.com by Dmitry.G...@gmail.com on 17 Oct 2012 at 5:53

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

No branches or pull requests

1 participant