首页 技术 正文
技术 2022年11月19日
0 收藏 905 点赞 4,396 浏览 2627 个字

.NET Core 2.0和ASP.NET Core 2.0正式版抢先体验

.NET Standard 2.0 is final

Broad platform support. .NET Standard 2.0 is supported on the following platforms:

  • .NET Framework 4.6.1
  • .NET Core 2.0
  • Mono 5.4
  • Xamarin.iOS 10.14
  • Xamarin.Mac 3.8
  • Xamarin.Android 7.5
  • UWP is work in progress and will ship later this year.

https://github.com/dotnet/standard/issues/439

.NET Core 2.0 正式版NuGet库: https://dotnet.myget.org/gallery/dotnet-2-0-0-rtm

.NET Core 2.0 正式版发布时间将会在.NET Conf 上发布。具体时间为9月18日或19日。

.NET Core 2.0.1 SDK Windows x64下载

https://dotnetcli.blob.core.windows.net/dotnet/Sdk/release/2.0.0/dotnet-sdk-latest-win-x64.exe

更多版本下载:https://github.com/dotnet/cli/tree/release/2.0.0

下面来正式体验。本文使用sdk 压缩包。

新建项目

dotnet –info

.NET Core 2.0和ASP.NET Core 2.0正式版抢先体验

Console

新建项目 dotnet new console

在项目目录下添加 NuGet.Config 如下:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="dotnet-2-0-0-rtm" value="https://dotnet.myget.org/F/dotnet-2-0-0-rtm/api/v3/index.json" />
</packageSources>
</configuration>

添加 System.Data.SqlClient 包,使用dotnet add package 或者编辑csproj。

<Project Sdk="Microsoft.NET.Sdk">  <PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Data.SqlClient" Version="4.4.0" />
</ItemGroup></Project>

接着还原包

然后使用VS Code 打开文件夹,实现ado.net 获取DataTable。

编写代码如下:

using System;
using System.Data;
using System.Data.SqlClient;namespace adonetdemo
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
string connectionString = "Data Source=.;database=Note;uid=sa;pwd=xxx;";
SqlConnection conn = new SqlConnection(connectionString);
conn.Open();
SqlDataAdapter adapter = new SqlDataAdapter("select * from Notes",conn);
DataSet dataset = new DataSet();
adapter.Fill(dataset);
DataTable dt = dataset.Tables[];
foreach (var item in dt.Rows)
{
DataRow row=item as DataRow;
System.Console.WriteLine(row["Title"]);
}
System.Console.WriteLine("本文原创LineZero");
}
}
}

运行显示结果如下:

.NET Core 2.0和ASP.NET Core 2.0正式版抢先体验

MVC

新建项目 dotnet new mvc

Program.cs 已经精简如下:

    public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
} public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}

使用dotnet run 运行。

razor

新建项目 dotnet new razor

目录下会发现只有Pages 文件夹,然后只有视图页和视图对应的cs文件,代码也可以在视图页上编写。

.NET Core 2.0和ASP.NET Core 2.0正式版抢先体验

将Index改成如下:

<h3>@Model.Name</h3>Index.cshtml.cs 如下:

    public class IndexModel : PageModel
{
public string Name;
public void OnGet()
{
Name="LineZero Blog";
}
}

运行程序dotnet run:

.NET Core 2.0和ASP.NET Core 2.0正式版抢先体验

 

开发调试项目

本文使用VS Code ,版本: 1.14.2 C#插件版本:1.12.0

VS Code 首次使用的话需要确保C#插件全部下载完成如下图:

.NET Core 2.0和ASP.NET Core 2.0正式版抢先体验

最新版本VS 2017 15.3 应该也是支持.NET Core 2.0。

.NET Core 2.0和ASP.NET Core 2.0正式版抢先体验

选择Yes。

本部分使用adonetdemo 项目做演示。直接调试可以参考之前文章:使用VS Code从零开始开发调试.NET Core 1.1

使用附加调试进行调试。

.NET Core 2.0和ASP.NET Core 2.0正式版抢先体验

选择.NET Core Attach 这里在代码中加入Console.ReadKey();,使程序暂时不退出,然后附加。

点击调试,注意选择第一个,dotnet exec 。

.NET Core 2.0和ASP.NET Core 2.0正式版抢先体验

然后按任意键,开始进行调试

.NET Core 2.0和ASP.NET Core 2.0正式版抢先体验

可以正常调试,并显示信息。

最后.NET Core 2.0 的正式版微软正式发布还有一段时间,本文不代表最终.NET Core 2.0正式版。

如果你觉得本文对你有帮助,请点击“推荐”,谢谢。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,083
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,558
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,407
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,180
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,816
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,899