• 我的第一个.NET Core App Windows系统


    一、前言

    • 本篇开发环境?
      1、操作系统: Windows 10 X64
      2、SDK: .NET Core 2.0 Preview

    二、安装 .NET Core SDK

    image
    image

    三、熟悉命令(cmd)

    • 1、查看版本
    #使用命令提示符(cmd)或者Windows PowerShell
    dotnet --version
    
    • 2、可选参数介绍
    参数介绍(en)介绍(ken的翻译)
    new Initialize .NET projects. 初始化项目(相当于通过VS模板新建项目)
    restore Restore dependencies specified in the .NET project. 还原项目中的依赖(相当于VS创建ASP.NET MVC,添加相关依赖)
    run Compiles and immediately executes a .NET project. 启动项目
    build Builds a .NET project. 编译项目
    publish Publishes a .NET project for deployment (including the runtime). 发布项目(包含runtime)
    test Runs unit tests using the test runner specified in the project. 启动单元测试
    pack Creates a NuGet package. 创建nuget包
    migrate Migrates a project.json based project to a msbuild based project. 迁移基于project.json,以兼容msbuild的编译
    clean Clean build output(s). 清除项目中编译产生的输出
    sln Modify solution (SLN) files. 修改解决方案文件.sln
    add Add reference to the project. 添加引用
    remove Remove reference from the project. 移除引用
    list List reference in the project. 列出项目中的引用
    nuget Provides additional NuGet commands. 通过nuget参数并附加一些参数,可以进行nuget包管理的一些操作
    msbuild Runs Microsoft Build Engine (MSBuild). 使用msbuild进行编译
    vstest Runs Microsoft Test Execution Command Line Tool. 启动命令行测试工具
    -v/—version Display .NET Core SDK version. 查看.NET Core SDK版本
    -i/—info Display .NET Core information. 查看.NET Core 详细信息
    -d/—diagnostics Enable diagnostic output. 启用诊断
    -v/—verbosity Set the verbosity level of the command. 设置冗长命令集?
    -h/—help Show help. 查看帮助

    四、HelloWorld项目

    • 1、创建项目
    #使用命令提示符(cmd)或者Windows PowerShell
    #1、打开项目文件夹(如果没有就先创建好)
    d:
    cd d:projects
    
    #2、创建项目
    dotnet new console -o helloworld
    #dotnet new :创建&初始化项目
    #console : 模板类型(相当于VS创建项目选择控制台应用程序)
    #-o :指定output路径名,可以理解为项目文件夹名称,默认项目名称=项目文件夹名称,也可以用-n 单独指定项目名称
    #dotnet new console -n helloworld 效果等同于 dotnet new console -o helloworld
    
    #执行输出:
    The template "Console Application" was created successfully.
    
    Processing post-creation actions...
    Running 'dotnet restore' on helloworldhelloworld.csproj...
      Restoring packages for D:Projectshelloworldhelloworld.csproj...
      Installing Microsoft.NETCore.DotNetAppHost 2.0.0-preview2-25407-01.
      Installing Microsoft.Packaging.Tools 1.0.0-preview2-25401-01.
      Installing Microsoft.NETCore.DotNetHostResolver 2.0.0-preview2-25407-01.
      Installing NETStandard.Library 2.0.0-preview2-25401-01.
      Installing Microsoft.NETCore.Platforms 2.0.0-preview2-25405-01.
      Installing Microsoft.NETCore.DotNetHostPolicy 2.0.0-preview2-25407-01.
      Installing Microsoft.NETCore.App 2.0.0-preview2-25407-01.
      Generating MSBuild file D:Projectshelloworldobjhelloworld.csproj.nuget.g.props.
      Generating MSBuild file D:Projectshelloworldobjhelloworld.csproj.nuget.g.targets.
      Restore completed in 7.04 sec for D:Projectshelloworldhelloworld.csproj.
    
    Restore succeeded.
    
    #项目文件就在d:projectshellworld中
    
    • 2、输出结果分析
    #1、显示根据指定dotnet new console -o helloworld模板创建了项目
    The template "Console Application" was created successfully.
    
    #2、然后又主动调用了dotnet restore命令来还原项目的引用,主动安装依赖
    Processing post-creation actions...
    Running 'dotnet restore' on helloworldhelloworld.csproj...
      Restoring packages for D:Projectshelloworldhelloworld.csproj...
    
    • 3、运行
    cd d:projectshelloworld
    dotnet run
    
    #运行结果
    Hello World!
    
    # 恭喜你,你的第一个.NET Core应用程序就这么诞生了
    
    #源代码请查 d:projectshellworldProgram.cs 文件
    

    五、备注

    • 支持的项目模板
    TemplatesShort NameLanguageTags
    Console Application console [C#], F#, VB Common/Console
    Class library classlib [C#], F#, VB Common/Library
    Unit Test Project mstest [C#], F#, VB Test/MSTest
    xUnit Test Project xunit [C#], F#, VB Test/xUnit
    ASP.NET Core Empty web [C#] Web/Empty
    ASP.NET Core Web App (Model-View-Controller) mvc [C#], F# Web/MVC
    ASP.NET Core Web App (Razor Pages) razor [C#] Web/MVC/Razor Pages
    ASP.NET Core with Angular angular [C#] Web/MVC/SPA
    ASP.NET Core with React.js react [C#] Web/MVC/SPA
    ASP.NET Core with React.js and Redux reactredux [C#] Web/MVC/SPA
    ASP.NET Core Web API webapi [C#] Web/WebAPI
    Nuget Config nugetconfig   Config
    Web Config webconfig   Config
    Solution File sln   Solution
    Razor Page page   Web/ASP.NET
    MVC ViewImports viewimports   Web/ASP.NET
    MVC ViewStart viewstart   Web/ASP.NET


    利用好—help/-h 参数

    #示例:
    dotnet --help
    dotnet new --help
    dotnet restore --help
    dotnet new console --help
    dotnet new mvc --help
    
    .NET技术资料
  • 相关阅读:
    UITextField最大字符数和最大字节数的限制
    Python profiling
    Glow Android 优化实践
    当 NSDictionary 遇见 nil
    TCP/IP详解2 学习笔记---mbuf
    行业代码获取最近代码
    词语、句子相似度比较
    从word得到表格数据插入数据库(6位行业代码)
    python遍历数组获取下标
    计算机浮点数表示
  • 原文地址:https://www.cnblogs.com/zmj520/p/9509264.html
Copyright © 2020-2023  润新知