Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
let's say I have a windows application project in C#, source files are thisfile.cs,thatfile.cs,plus.cs. thatfile.cs needs to be compiled before thisfile.cs is compiled. inside MSBuild file such as .csproj, how the build order of C# source files are decided? more specifically, how CSC task in MSbuild decides the build order.

I am learning on MSBuild and have such a question for long time.
Thanks a million.
Posted
Comments
Sergey Alexandrovich Kryukov 22-Apr-15 10:39am    
Why? why?!
—SA
Southmountain 24-Apr-15 11:23am    
I feel you only beat around the bush and did not answer the question.
Sergey Alexandrovich Kryukov 24-Apr-15 14:27pm    
Did not answer? Interesting... Set aside apparent rudeness of your saying. Set aside that you are trying to manipulate me into feeling guilty for asking my legitimate "why" questions...
I've been wondering: didn't you afraid of exposing yourself in a way that most readers would very likely perceive as plain lie?
Probably you need to remember that people around can read all the available posts and make some opinions on who is who. I don't want to hurt you or anyone, I would like to advise on keeping things in good standing.

—SA

MSBuild project file standard offers you a declarative language used to formulate build rules, not imperative.

That said, there is no any predefined order of build steps, but you can created this order if you specify dependencies between targets, even if those dependencies are fake.

The specifications are crystal clear, it's hard to miss anything:
https://msdn.microsoft.com/en-us/library/dd393574.aspx[^],
https://msdn.microsoft.com/en-us/library/dd637714.aspx[^],
https://msdn.microsoft.com/en-us/library/ms171469.aspx[^],
https://msdn.microsoft.com/en-us/library/0k6kkbsd.aspx[^].

Now, let's get to C#. This is the language where the order of source code files is totally irrelevant. In the compiler command line syntax, you just supply a list of those files (or even directories with files) in arbitrary order. Naturally, that is what that predefined build task does to those file. This part of the question makes no real sense.

—SA
 
Share this answer
 
Comments
Southmountain 22-Apr-15 21:41pm    
Thanks for the links. I browsed them and some of them I am very familiar, but it does not answer my question.

could you explain rationale behind that MSBuild project file standard offers you a declarative language used to formulate build rules, so that build order does not matter?

in my mind, MSBuild is kind of Make tool. if we use command line csc.exe to compile several C# files, the order matters too.
Sergey Alexandrovich Kryukov 22-Apr-15 22:29pm    
It does answer your question. Order matters? No. Period.
Order of projects does matter, so source files from different project are partially ordered, in that sense, but it can be left beyond the brackets. And I answered how the order of projects is defined.
—SA
Is there more than one project?

If yes, compiler uses project's references to decide wich project must be compiled first, second, and so on.

If there is only one project, order doesn't matter.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900