为什么"副本,如果新的"没有复制文件时,文件被更新?文件、副本、QUOT

2023-09-04 10:33:25 作者:我太难了

我在Visual Studio中前preSS的解决方案是这样的:

LogicSchema 类在C#中,将分析在运行时指定的XML文件。以下是在方法的Program.cs

  LogicSchema LS =新LogicSchema(
    XDocument.Load(
        模式\\ C#SCHEMA.XML
        。LoadOptions preserveWhitespace));
 

我在我的解决方案,称为模式,以保存XML文件,并设置生成操作的内容创建的文件夹的和复制到输出目录的数值的复制,如果新的。

我的期望是,如果用记事本打开该文件,进行更改,并保存,XML文件的更新版本将被复制到输出中的目录(在这种情况下,斌\调试),当我preSS F5。但是,更新的文件不会被复制到输出目录,除非我选择重建。普通的构建不起作用。

什么我需要改变,这样,当我preSS F5,将文件复制到当它被更新输出目录?

解决方案   

这似乎也是在Visual Studio 2008的工作团队系统 -   必须是防爆pression特定版本,所以不能瑞普...

OK,我原来的猜测是不正确的 - 这是关于引用库中的XML文件之中。现在可以摄制了。

我觉得最自然的方式是将嵌入XML作为资源,然后用 GetManifestResourceStream阅读()。这样一来,XML文件将按照你的DLL,你引用它,没有它单独复制,即使你而不是直接引用该dll通过项目的参考。

...或者,你可以使用pre-build事件? (项目属性 - 生成事件):

 复制$(PROJECTDIR)的test.xml $(SolutiontDir)projectFolder \斌\调试\的test.xml
 

我想就算VS认为没有文件已更改源将始终运行。至少在全VS2008是这样的话 - 只是测试

免费下载百度文库Word文档原格式文件 这个神技能知道的人没几个

I have a solution in Visual Studio Express that looks like this:

The LogicSchema class in C# that will parse a specified XML file at run-time. The following is in the main method of Program.cs:

LogicSchema ls = new LogicSchema(
    XDocument.Load(
        "schemas\\C#Schema.xml",
        LoadOptions.PreserveWhitespace));

I created a folder in my solution called "schemas" to save the XML file and set the Build Action to Content and the "Copy to Output Directory" value to be Copy if newer.

My expectation is that if open the file in notepad, make a change, and save it, the updated version of the XML file will be copied to the ouput directory (in this case, bin\debug) when I press F5. However, the updated file is not copied to the output directory unless I select Rebuild. Regular Build does not work.

What do I need to change so that when I press F5, the file is copied to the output directory when it's been updated?

解决方案

It seems to work also in Visual Studio 2008 Team System - must be Expression edition specific, so cannot repro...

OK, my original guess was not true - it is about XML file being in the referenced library. Can repro it now.

I think the most natural way would be to embed the XML as resource and then read it with GetManifestResourceStream(). This way, the XML file would follow your dll as you reference it without copying it separately even if you reference the dll directly and not through project reference.

...or then you could use Pre-build event? (Project properties - Build Events):

copy $(ProjectDir)test.xml $(SolutiontDir)projectFolder\bin\debug\test.xml

I would think it will always run even if VS thinks no source files have changed. At least in full VS2008 this is the case - just tested.