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