在进行BeforeBuild处理后,如何使Visual Studio重新读取源文件? [英] How to get Visual Studio to reread source files after BeforeBuild processing?

查看:125
本文介绍了在进行BeforeBuild处理后,如何使Visual Studio重新读取源文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了一个C#预处理程序,通过使用BeforeBuild MSBuild目标调用它可以将其合并到.csproj项目中.除预处理器已修改项目中的一个或多个C#源文件(很少发生)外,C#编译步骤使用源文件的缓存版本,这一点行之有效.构建完成后,Visual Studio会提示我文件名-此或该文件已在源代码编辑器外部修改.是否要重新加载它?".因此,我必须回答是"并重建项目,以使其能够使用修改后的源文件.

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.

是否有某种方法可以使Visual Studio检测到源文件已被修改并在其编译步骤中使用更新的版本?还是应该以其他方式调用预处理器,而不是使用BeforeBuild目标?

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?

推荐答案

这不是最佳解决方案,但这是我到目前为止提出的最好的解决方案.

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

如此处所述 http://social.msdn.microsoft.com/Forums/zh-CN/vsdebug/thread/6c042390-0782-4afe-94be-9746d75f5d34/您可以放置​​

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

 <UseHostCompilerIfAvailable>false</UseHostCompilerIfAvailable>

在.csproj文件中,这将使Visual Studio使用常规" C#编译器,而不是使用缓存文件的内部"编译器.这大概会降低性能,但我没有注意到它,也没有尝试对其进行衡量.

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.

而且,如此处所述 http://startbigthinksmall.wordpress.com/2009/03/16/visual-studio-tipp-auto-refresh-file-changes/,您可以使Visual Studio停止对更新的文件na,重新加载它们.

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.

我还是希望找到某种方法来告诉Visual Studio更新其缓存的文件,然后调用其内部编译器...

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.

这篇关于在进行BeforeBuild处理后,如何使Visual Studio重新读取源文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆