简体   繁体   中英

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?

Both files are included in the project. The project is of Web Application type, so everything compiles into a single dll when deploying. I am not sure if during compilation, the .bak file is ignored.

I am working on a project in Visual Studio, in which some past developer has included both these files within the project.

If you click on the file in Solution Explorer and look at the Properties window, you'll see a property called "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.

As far as I know (and check), by default , a *.bak file is not considered as a C# class file in a VS Project. 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.

You can always tell to VS to treat it as a compilable c# file: Properties -> Build Action -> Compile.

It's just look like a backup (bak) source file - just for history purposes, I assume.

No.

The .bak file is treated as a normal text file.

This is quite easy to test. Create a new class file, with a class name foo .

Now create a new .cs.bak file and type in the same code.

when you compile the project, you would expect a duplicate class declaration error - this does not occur.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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