3

I've written a C# preprocessor that I've incorporated into my .csproj projects by invoking it using the BeforeBuild MSBuild target. This works OK except that when the preprocessor has modified one or more of the C# source files in the project (happens fairly seldom) the C# compile step uses a cached version of the source file. After the build is complete Visual Studio prompts me with a message "filename-this-or-that This file has been modified outside of the source editor. Do you want to reload it?". So then I have to reply Yes and rebuild the project to get it to use the modified source files.

Is there some way to get Visual Studio to detect that the source files have been modified and use the updated versions in its compile step? Or should I be invoking my preprocessor in some other way rather than using the BeforeBuild target?

RenniePet
  • 11,420
  • 7
  • 80
  • 106

1 Answers1

2

This isn't an optimal solution, but it's the best I've come up with so far.

As documented here http://social.msdn.microsoft.com/Forums/en-US/vsdebug/thread/6c042390-0782-4afe-94be-9746d75f5d34/ you can place

 <UseHostCompilerIfAvailable>false</UseHostCompilerIfAvailable>

in the .csproj file, and that gets Visual Studio to use the "normal" C# compiler instead of the "internal" one that uses the cached files. This presumably reduces performance, but I haven't noticed it, or tried to measure it.

And, as documented here http://startbigthinksmall.wordpress.com/2009/03/16/visual-studio-tipp-auto-refresh-file-changes/ you can get Visual Studio to stop nagging you about the updated files, and simply reload them.

I would still prefer to find some way of telling Visual Studio to update its cached files and then invoke its internal compiler ...

I'm marking this as "the answer", but I'd still like to hear better possibilities, and if that happens I'll unmark this one.

RenniePet
  • 11,420
  • 7
  • 80
  • 106