如何确定C#源文件的构建顺序? [英] how the build order of C# source files are decided?

查看:71
本文介绍了如何确定C#源文件的构建顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在C#中有一个Windows应用程序项目,源文件是thisfile.cs,thatfile.cs,plus.cs。在编译thisfile.cs之前需要编译thatfile.cs。在MSBuild文件中如.csproj,如何确定C#源文件的构建顺序?更具体地说,MSbuild中的CSC任务如何决定构建顺序。



我正在学习MSBuild并且长时间有这样的问题。

万分感谢。

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.

推荐答案

MSBuild项目文件标准为您提供了用于制定构建规则的声明性语言,而不是命令式



也就是说,没有任何预定义的构建步骤顺序,但如果指定依赖项,则可以创建此顺序目标之间,即使这些依赖是假的。



规格非常清晰,很难错过任何东西:

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 [ ^ ]。



现在,让我们来看看C#。这是源代码文件的顺序完全无关的语言。在编译器命令行语法中,您只需按任意顺序提供这些文件(甚至包含文件的目录)的列表。当然,这就是预定义的构建任务对这些文件的作用。问题的这一部分没有任何意义。



-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


是否有超过一个项目?



如果是,编译器使用项目的引用来决定必须先编译项目,第二,等等。



如果只有一个项目,订单无关紧要。
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.


这篇关于如何确定C#源文件的构建顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆