如何让 Visual Studio 在 BeforeBuild 处理后重新读取源文件?
我编写了一个 C# 预处理器,通过使用 BeforeBuild MSBuild 目标调用它,将其合并到我的 .csproj 项目中。除了当预处理器修改了项目中的一个或多个 C# 源文件(这种情况很少发生)时,C# 编译步骤使用源文件的缓存版本之外,此方法工作正常。构建完成后,Visual Studio 会提示我一条消息“文件名-此-或-该文件已在源代码编辑器之外进行了修改。是否要重新加载它?”。所以我必须回答“是”并重建项目以使其使用修改后的源文件。
有没有某种方法可以让 Visual Studio 检测到源文件已被修改并在其编译步骤中使用更新的版本?或者我应该以其他方式调用我的预处理器而不是使用 BeforeBuild 目标?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不是最佳解决方案,但这是迄今为止我想到的最好的解决方案。
如此处所述 http://social.msdn.microsoft.com/Forums/en-US/vsdebug/thread/6c042390-0782-4afe-94be-9746d75f5d34/ 您可以将其放入
.csproj 文件中,这会让 Visual Studio 使用“普通”C# 编译器,而不是使用缓存文件的“内部”编译器。这可能会降低性能,但我没有注意到它,也没有尝试测量它。
并且,如此处记录的 http:// /startbigthinksmall.wordpress.com/2009/03/16/visual-studio-tipp-auto-refresh-file-changes/ 您可以让 Visual Studio 停止对您的烦扰更新文件,只需重新加载它们即可。
我仍然希望找到某种方法来告诉 Visual Studio 更新其缓存文件,然后调用其内部编译器...
我将其标记为“答案”,但我仍然想听到更好的可能性,如果发生这种情况我会取消标记这个。
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
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.