.csproj 文件有什么作用?
通常,C# 项目有一个与其关联的 .csproj 文件。那个文件是做什么用的?它包含什么数据?
Usually a C# project has a .csproj file associated with it. What is that file for? What data does it contain?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
基本上,.csproj 文件包含项目中的文件列表,以及对系统程序集的引用等。
有一大堆设置 - Visual Studio 版本、项目类型、程序集名称、应用程序图标、目标区域性、安装 URL。 ..
构建项目所需的一切。虽然您可以假设您需要当前文件夹中的所有内容,但拥有明确的列表可以让您在磁盘和项目中对它们进行逻辑组织,以便您可以更轻松地找到所需的文件。
它只是 XML,因此您可以在您喜欢的文本编辑器中打开它并查看。
每个程序集都有一个 .csproj 文件,而 .sln(解决方案文件)将构成项目的所有程序集联系在一起。
Basically the .csproj file contains the list of files in your project, plus the references to system assemblies etc.
There are a whole bunch of settings - Visual Studio version, project type, Assembly name, Application Icon, Target Culture, Installation Url,...
Everything you need to build your project. While you could assume that you need everything in the current folder, having an explicit list allows you to organise them logically both on the disk and in the project so you can more easily find the files you want.
It's just XML so you can open it in your favourite text editor and take a look.
You get one .csproj file per assembly and the .sln (solution file) ties together all the assemblies that make up your project.
针对 .NET 5 进行了更新
这是我们应用程序中最重要的文件。它告诉 .NET 如何构建项目。
所有 .NET 项目都在
.csproj
文件中列出其依赖项。如果您以前使用过 JavaScript,请将其视为 package.json 文件。不同之处在于,这是一个 XML 文件,而不是 JSON。当您运行 dotnet Restore 时,它会使用此文件来确定要下载哪些 NuGet 包并将其复制到项目文件夹。.csproj
文件还包含 .NET 工具构建项目所需的所有信息。它包括正在构建的项目的类型(控制台、Web、桌面等)、该项目的目标平台以及对其他项目或第三方库的任何依赖项。从 .NET 5 开始,进行了一些重大更改,以使该文件更易于阅读和维护,如下所列。
.csproj
文件中。现在它们会被自动包含和编译。**示例:
注意:如果您使用的是 Visual Studio,此文件将被隐藏,但您可以右键单击该项目并选择编辑项目文件。
Updated for .NET 5
This is the most important file in our application. It tells .NET how to build the project.
All .NET projects list their dependencies in the
.csproj
file. If you have worked with JavaScript before, think of it like a package.json file. The difference is, instead of a JSON, this is an XML file. When you run dotnet restore, it uses this file to figure out which NuGet packages to download and copy to the project folder.The
.csproj
file also contains all the information that .NET tooling needs to build the project. It includes the type of the project being built (console, web, desktop, etc.), the platform this project targets and any dependencies on other projects or 3rd party libraries.Starting in .NET 5, there have been a few major changes to make this file easier to read and maintain, which are listed below.
.csproj
file. Now they are automatically included and compiled.**Example:
Note: If you are using Visual Studio, this file will be hidden, but you can right-click on the project and choose edit the project file.
该文件包含要作为项目一部分进行编译的所有文件的列表,以及其他选项,例如项目名称、发布和调试配置、编译选项等。
The file contains a list of all the files to be compiled as part of the project, as well as other options like the project name, release and debug configurations, compilation options, and so on.
摘自 什么是 .csproj 文件?
Taken from What is .csproj file?
它包含有关项目中使用的所有文件、使用的程序集(包括其他随后提供的程序集的路径)、输出类型、程序集名称等等的信息。因此,通过打开此 xml,您可以在下一个中找到所有信息屋顶。
It contains information about all the files used in the project, assemblies used(including the path for other then provided assemblies), output type, assembly name and much more.So, by opening this xml, you can find all the info in under one roof.