0
votes

Example when I compile all cs files to a single assembly(say Single.dll), but When I mention the file extension as random text, as mentioned below

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc -target:library -out:Single.abc *.cs

It is not throwing error, but creates a file as "Single.abc"

what is the purpose of doing this kind of compilation?

See example here: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-options/command-line-building-with-csc-exe

1
By the same token, why does Notepad allow you to create a plain text file with an .abc extension, why does your file archiver of choice allow you to create a ZIP file with an .abc extension, why will any operating system's file manager allow you to change to any file's extension to any string of characters you want, whether it accurately reflects the contents or not? Or, better yet, why shouldn't those applications allow you to do that? That is, why should they care what extension you use? - Lance U. Matthews
csc doesn't impose any restrictions on input file extensions, either.. Related: C# compiler compiles .txt .obj .java files. - Lance U. Matthews
Hmm,, I see it is just a provision provided - Samuel A C

1 Answers

1
votes

You get what you would have got if you had asked for Single.dll, except with Single.abc as the name. You specifically asked for the compiler to do this. The compiler understood your request and did what you asked. Who knows, perhaps you chose a .abc extension so that it wouldn't be blocked by an e-mail client when you send it to someone else.

The compiler doesn't just give up and print an error message, because there is no reason why it should. It would require additional code to have been written for the express purpose of rejecting a case where it isn't even clear it's an error.