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程序