当前位置: 首页 > news >正文

C#,入门教程(07)——软件项目的源文件与目录结构

上一篇:

C#,入门教程(06)——解决方案资源管理器,代码文件与文件夹的管理工具icon-default.png?t=N7T8https://blog.csdn.net/beijinghorn/article/details/124895033

创建新的 C# 项目后, Visual Studio 会自动创建一系列的目录与文件。
程序员后面的工作就是在这个目录及这些文件的基础上进行的。
本文对这些目录与文件做一个概要性的解释。

一、目录

1、默认的目录

Visual Studio 默认创建 3 个子目录及下层的目录。

\bin
\---Debug
\---Release
\obj
\---Debug
\---Release
\Properties

\bin 目录保存项目生成的程序集(.exe 或 .dll)
\bin\Debug 保存“调式版本Debug”模式的文件,一般都是在这个目录下能找到可执行文件 .exe
\bin\Release  保存“正式发布版本Release”模式的文件

\obj 目录保存项目的编译临时文件(一般无需操心)
\obj\Debug 保存“调式版本Debug”模式的文件
\obj\Release 保存“正式发布版本Release”模式的文件

\Properties 目录保存项目相关的一些设置信息,一般无需阅读与修改。


2、改良与更好的目录结构

建议在工程目录下创建 App_Code 子目录,用以保存工程相关的所有 namespace 的 class 文件。
并且按类别予以区分。比如,幸运之门50018.COM的目录结构:

\App_Code
\App_Code\Basic  存储常用的 Helper 类的基础静态类
\App_Code\K50018 存储核心数据分类代码
\App_Code\K50018\Basic 数据分析的基础代码
\App_Code\K50018\Entity 数据体(从数据库、文件获得)的相关代码
\App_Code\K50018\Algorithm 数据分析的算法代码
\App_Code\K50018\Graph 生成走势图表等分析结果的代码
。。。

请,举一反三!

二、文件

工程相关的文件分类两类:(1)*.cs 是C#源代码类;(2)*.else 其他类;

1、.sln 解决方案(solution)文件

.sln 是解决方案的配置文件,保存着项目project和解决方案的关系。
这个文件也是双击打开 Visual Studio 的默认文档。

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.1.32228.430
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Desktop", "Desktop.csproj", "{D87DE9F7-951F-4392-A24B-64DF168191CA}"
EndProject
。。。

2、.csproj 工程项目(C sharp project)文件

.csproj 为c sharp project的缩写。
.csproj 项目文件,保存着源代码、其他文档、资源和本项目的归属关系。
用编辑器(推荐韩国人写的Editplus!)打开 Desktop.csproj 文件,可以看到类似这样的(XML)内容:

。。。

<ItemGroup><Compile Include="App_Code\K50018\Basic\Statistics.cs" /><Compile Include="App_Code\K50018\Algorithm\Prime.cs" /><Compile Include="App_Code\K50018\Graph\Trend.cs" />
。。。<Compile Include="Form1.cs"><SubType>Form</SubType></Compile><Compile Include="Form1.Designer.cs"><DependentUpon>Form1.cs</DependentUpon></Compile><Compile Include="Program.cs" />


。。。

3、App.config 项目配置文件

App.config 一般是这样的XML内容。

<?xml version="1.0" encoding="utf-8" ?>
<configuration><startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" /></startup>
</configuration>

4、Form 相关文件

(1)Form 相关

Form 是指软件的窗口。Form 相关文件是3个一组。

Form1.cs (窗口事件处理的)源代码
Form1.Designer.cs 窗口设计的源代码(初学者略过)
Form1.resx 窗口设计的资源信息(初学者掠过)

Form1.cs 一般是这样的内容:

// 引用系统的命名空间

using System;
using System.IO;
using System.Text;
using System.Data;
using System.Linq;
using System.Drawing;
using System.Threading;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Windows.Forms;// 引用自己开发的命名空间
using Legalsoft.K50018;namespace Desktop_Application
{public partial class Form1 : Form{// 默认构造函数public Form1(){InitializeComponent();}// 窗口加载时候的处理private void Form1_Load(object sender, EventArgs e){}// button1 点击事件的处理private void button1_Click(object sender, EventArgs e){//一般的代码都从这里起飞!}}
}

Form1.Designer.cs的内容一般这样:

namespace Desktop_Application
{partial class Form1{/// <summary>/// 必需的设计器变量。/// </summary>private System.ComponentModel.IContainer components = null;/// <summary>/// 清理所有正在使用的资源。/// </summary>/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>protected override void Dispose(bool disposing){if (disposing && (components != null)){components.Dispose();}base.Dispose(disposing);}#region Windows 窗体设计器生成的代码/// <summary>/// 设计器支持所需的方法 - 不要修改/// 使用代码编辑器修改此方法的内容。/// </summary>private void InitializeComponent(){this.panel1 = new System.Windows.Forms.Panel();this.button1 = new System.Windows.Forms.Button();this.panel2 = new System.Windows.Forms.Panel();this.webBrowser1 = new System.Windows.Forms.WebBrowser();this.panel1.SuspendLayout();this.panel2.SuspendLayout();this.SuspendLayout();。。。}}
}

Form1.resx 窗口设计的资源信息(初学者掠过)

<?xml version="1.0" encoding="utf-8"?>
<root><!-- Microsoft ResX Schema Version 2.0The primary goals of this format is to allow a simple XML format that is mostly human readable. The generation and parsing of the various data types are done through the TypeConverter classes associated with the data types.。。。-->
</root>


(2)更多的窗口

如果软件设计有多个窗口,则就具有多个配套的文件。常见的有:

欢迎窗口
Welcome.cs (窗口事件处理的)源代码
Welcome.Designer.cs 窗口设计的源代码(初学者略过)
Welcome.resx 窗口设计的资源信息(初学者掠过)

软件配置窗口
Setting.cs (窗口事件处理的)源代码
Setting.Designer.cs 窗口设计的源代码(初学者略过)
Setting.resx 窗口设计的资源信息(初学者掠过)

软件帮助窗口
Help.cs (窗口事件处理的)源代码
Help.Designer.cs 窗口设计的源代码(初学者略过)
Help.resx 窗口设计的资源信息(初学者掠过)

再见!
Bye.cs (窗口事件处理的)源代码
Bye.Designer.cs 窗口设计的源代码(初学者略过)
Bye.resx 窗口设计的资源信息(初学者掠过)


三、更多的项目!!!

压轴的,都是精彩的!

《幸运之门彩票网50018.COM》 有这样一系列的实际需求:
(1)网站:运行于 Windows Server 2008 之 IIS 的 Web 服务;
     需要 App_Code 下的所有代码支持的功能;
(2)合作:运行于合作伙伴 Linux 之 Web 服务;
     需要 App_Code 下的所有代码支持的功能;
(3)桌面PC:《蓝彩和app》;
     需要 App_Code 下的所有代码支持的功能;
(4)安卓(Andriod)App:《蓝彩和app》;
     需要 App_Code 下的所有代码支持的功能;
(5)苹果(iOS)App:《蓝彩和app》;
     需要 App_Code 下的所有代码支持的功能;
(6)合作伙伴Unity游戏软件内的《CaiPiao分析》;
     需要 App_Code 下的主要代码支持的功能;

于是,在我的工程目录下就有了这样一些文件:

App.config
Desktop.csproj 桌面PC软件
Desktop.sln
Web.csproj IIS网站,WEB服务
Web.sln
Linux.csproj LINUX,WEB服务
Linux.sln
MAPP-Andriod.csproj 安卓app
MAPP-Andriod.sln
MAPP-iOS.csproj 苹果app
MAPP-iOS.sln
Unity.csproj 游戏Unity app
Unity.sln
Form1.cs
Form1.Designer.cs
Form1.resx
Welcome.cs
Welcome.Designer.cs
Welcome.resx
Setting.cs
Setting.Designer.cs
Setting.resx
Help.cs
Help.Designer.cs
Help.resx
Bye.cs
Bye.Designer.cs
Bye.resx

重要的是!仅仅只需要维护一个 App_Code !!!

C# 是无与伦比的!

下一篇:

C#,入门教程(08)——基本数据类型及使用的基础知识icon-default.png?t=N7T8https://blog.csdn.net/beijinghorn/article/details/123906998


 

http://www.lryc.cn/news/286400.html

相关文章:

  • 三国游戏(第十四届蓝桥杯)
  • k8s---包管理器helm
  • 对于超低延迟SSD,IO调度器已经过时了吗?-part2
  • 【C++】list的使用
  • mybatis的缓存机制
  • ChatGLM3报错:No chat template is defined for this tokenizer
  • 大数据学习之Flink、搞懂Flink的恢复策略
  • C语言易忘操作符全集
  • 网络请求 mvp mvvm get post delete put 请求
  • 研究生开题报告撰写:文言一心VSChatgpt3.5
  • Unity animator动画倒放的方法
  • Dubbo源码解析第一期:如何使用Netty4构建RPC
  • unity刷新grid,列表
  • 蓝桥杯备赛 day 3 —— 高精度(C/C++,零基础,配图)
  • 人形机器人创新发展顶层设计与关键技术布局
  • C语言-算法-最小生成树
  • android 扫描某个包下的所有类
  • 远程ssh 不通的原因之一
  • wamp集成环境部署
  • 使用antd design pro 及后端nodejs express 结合minio进行文件的上传和下载管理
  • Unity常用的优化技巧集锦
  • c++动态调用dll
  • 使用Python自动化操作手机,自动执行常见任务,例如滑动手势、呼叫、发送短信等等
  • E - Souvenir(图论典型例题)
  • 【SpringBoot篇】添加富文本编辑器操作
  • 前台vue配置
  • 牛客周赛 Round 18 解题报告 | 珂学家 | 分类讨论计数 + 状态DP
  • CentOS防火墙基本操作
  • Shell脚本的编程规范和变量类型
  • C++面试:跳表