C Sharp/开发环境

维基教科书,自由的教学读本

CSharp > 开发环境


SDK[编辑]

.Net Framework[编辑]

Mono[编辑]

Windows[编辑]

  1. Mono官方下载网点下载 Windows 版安装程式。
  2. 执行安装程式,并遵循他的导引即可。

Linux/Unix[编辑]

Ubuntu

Ubuntu Linux本身已经包含w所以只要以 apt-get 安装即可:

$ sudo apt-get install mono mono-jit mono-utils mono-mcs mono-assemblies-arch mono-assemblies-base mono-common libmono0 mono-devel
Debian

安装步骤与 Ubuntu Linux 相同,但可能需要先自行编修 apt repository 档案,添加

deb http://people.debian.org/~formorer/mono backports main

参考资料:Mono for Debian

Fedora Core

Core 4 (含)以前,请到 [www.mono-project.com/Downloads 官方下载网站] 下载必要的 rpm 进行安装。[www.mono-project.com/Downloads 官方下载网站]也有提供必要的 yum repository 档案,让你可以轻松的使用 yum 来安装。至于 Core 5 已经包含在内。

RHEL/CentOS/WBEL

步骤类似 Fedora Core。

Mac OS[编辑]

IDE[编辑]

Visual Studio[编辑]

  • Visual Studio,只支援Windows。内建包含.Net Framework的安装。
    其中的 Community 或 Express 是没有使用天数限制的,如果具有学生的身份,也可以到Dreamspark下载Pro版。

Visual Studio Code[编辑]

  1. 下载安装.NET Core SDK
  2. 安装C# extension for VS Code
  3. 使用dotnet.exe,可以完成创建solution、创建propject、编译、运行、依赖包下载管理等各种操作,详情见[1]
    1. 在VSC中打开一个文件夹
    2. 在VSC中的Terminal执行dotnet new <prototype> 创建某个项目类型,如console
    3. 执行dotnet run
    4. 在VSC中可以正常调式
      • 建议打开.vscode/launch.json,将 console 设置从 internalConsole 更改为 integratedTerminal:

JSON

      • 在debug console”窗口底部的提示符处输入 name = "Gracie",然后按 Enter。 可更改变量值
    1. 发布程序:dotnet publish --configuration Release 生成的既有.exe也有.dll 在命令提示符处输入 dotnet HelloWorld.dll 可执行。在VSC的“资源管理器”中,右键单击“发布”文件夹,然后选择“在终端中打开”,也可以执行exe或dll。

StringLibraryTest/UnitTest1.cs的代码如下:

dotnet new sln
dotnet new classlib -o StringLibrary
dotnet sln add StringLibrary/StringLibrary.csproj
dotnet build
dotnet new console -o ShowCase #create a test project
dotnet sln add ShowCase/ShowCase.csproj
dotnet add ShowCase/ShowCase.csproj reference StringLibrary/StringLibrary.csproj
dotnet run --project ShowCase/ShowCase.csproj
dotnet new mstest -o StringLibraryTest # create a unit test project
dotnet add StringLibraryTest/StringLibraryTest.csproj reference StringLibrary/StringLibrary.csproj
dotnet test StringLibraryTest/StringLibraryTest.csproj
dotnet test StringLibraryTest/StringLibraryTest.csproj --configuration Release

dotnet add package Newtonsoft.Json # add a package's reference to the current project.
using Microsoft.VisualStudio.TestTools.UnitTesting;
using UtilityLibraries;

namespace StringLibraryTest;

[TestClass]
public class UnitTest1
{
    [TestMethod]
    public void TestStartsWithUpper()
    {
        // Tests that we expect to return true.
        string[] words = { "Alphabet", "Zebra", "ABC", "Αθήνα", "Москва" };
        foreach (var word in words)
        {
            bool result = word.StartsWithUpper();
            Assert.IsTrue(result,
                   string.Format("Expected for '{0}': true; Actual: {1}",
                                 word, result));
        }
    }

    [TestMethod]
    public void TestDoesNotStartWithUpper()
    {
        // Tests that we expect to return false.
        string[] words = { "alphabet", "zebra", "abc", "αυτοκινητοβιομηχανία", "государство",
                               "1234", ".", ";", " " };
        foreach (var word in words)
        {
            bool result = word.StartsWithUpper();
            Assert.IsFalse(result,
                   string.Format("Expected for '{0}': false; Actual: {1}",
                                 word, result));
        }
    }

    [TestMethod]
    public void DirectCallWithNullOrEmpty()
    {
        // Tests that we expect to return false.
        string?[] words = { string.Empty, null };
        foreach (var word in words)
        {
            bool result = StringLibrary.StartsWithUpper(word);
            Assert.IsFalse(result,
                   string.Format("Expected for '{0}': false; Actual: {1}",
                                 word == null ? "<null>" : word, result));
        }
    }
}

MonoDevelop[编辑]

Borland C# Builder[编辑]

SharpDevelop[编辑]

Eclipse+plugin[编辑]

  1. 使用 Visual Studio Code 创建 .NET程序