简体   繁体   English

Visual Studio 2012中具有.bak扩展名的类文件

[英]Class file with .bak extension in Visual Studio 2012

Is a class file like MyClass.cs.bak used at run-time even though there is a class file by the name of MyClass.cs within the same Visual Studio project? 即使在同一Visual Studio项目中有一个名为MyClass.cs的类文件,运行时是否仍使用诸如MyClass.cs.bak之类的类文件?

Both files are included in the project. 这两个文件都包含在项目中。 The project is of Web Application type, so everything compiles into a single dll when deploying. 该项目属于Web应用程序类型,因此在部署时所有内容都编译为一个dll。 I am not sure if during compilation, the .bak file is ignored. 我不确定在编译过程中是否会忽略.bak文件。

I am working on a project in Visual Studio, in which some past developer has included both these files within the project. 我正在Visual Studio中的一个项目上工作,以前的开发人员在其中将这两个文件都包含在项目中。

If you click on the file in Solution Explorer and look at the Properties window, you'll see a property called "Build Action". 如果在解决方案资源管理器中单击文件,然后查看“属性”窗口,您将看到一个名为“ Build Action”的属性。 This defines whether the file will be treated like code ("Compile"), included as a resource ("Embedded Resource"), or ignored ("None"). 这定义了将文件视为代码(“编译”),作为资源(“嵌入式资源”)包含还是忽略(“无”)。

When a file is added to a project, the default Build Action is selected based on the file extension. 将文件添加到项目时,将基于文件扩展名选择默认的“构建操作”。 For .bak files, which have no particular meaning to C# projects, the default "None" should be selected, and the file will be ignored when compiling the project. 对于.bak文件,这些文件对C#项目没有特殊意义,应选择默认的“无”,并且在编译项目时将忽略该文件。

As far as I know (and check), by default , a *.bak file is not considered as a C# class file in a VS Project. 据我了解(并检查), 默认情况下*.bak文件在VS Project中视为C#类文件。 It's just another text file which doesn't complied into the assembly as a class module - Therefore, by the way, why you don't get duplicate class names declaration exception. 这只是另一个文本文件,没有作为class模块编译到程序集中-因此,顺便说一句,为什么您没有得到重复的类名声明异常。

You can always tell to VS to treat it as a compilable c# file: Properties -> Build Action -> Compile. 您总是可以告诉VS将其视为可编译的c#文件: 属性->生成操作->编译。

It's just look like a backup (bak) source file - just for history purposes, I assume. 它看起来就像一个备份(bak)源文件-我想只是出于历史目的。

No. 没有。

The .bak file is treated as a normal text file. .bak文件被视为普通文本文件。

This is quite easy to test. 这很容易测试。 Create a new class file, with a class name foo . 创建一个新的类文件,其类名为foo

Now create a new .cs.bak file and type in the same code. 现在创建一个新的.cs.bak文件,并输入相同的代码。

when you compile the project, you would expect a duplicate class declaration error - this does not occur. 编译项目时,可能会出现重复的类声明错误-不会发生。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM