日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無先后,達(dá)者為師

網(wǎng)站首頁 編程語言 正文

C#生成帶注釋的dll并引用實(shí)現(xiàn)_C#教程

作者:博弈星宇 ? 更新時間: 2022-06-02 編程語言

一. 編寫.cs文件

注:要想編譯dll中注釋可用,則代碼中的注釋要用“ /// ” 來進(jìn)行注釋,否則編譯后注釋不起作用。

注釋是生成在XML文件中的。

ComputeDemo.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace MetaDataTest1
{
    /// <summary>
    /// 類名:ComputeDemo
    /// </summary>
    public class ComputeDemo
    {
        /// <summary>
        /// 加法
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public int Add(int a, int b)
        {
            return a + b;
        }
        /// 減法
        public int Sub(int a, int b)
        {
            return a - b;
        }
        /// 乘法
        public int Multi(int a, int b)
        {
            return a * b;
        }
        ///除法
        public double Div(int a, int b)
        {
            return a / b;
        }
    }
}

Program.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace MetaDataTest1
{
    class Program
    {
        static void Main(string[] args)
        {
            var obj = new ComputeDemo();
            int addResult = obj.Add(1, 2);
            Console.WriteLine(addResult);
            Console.ReadKey();
        }
    }
}

二. 生成XML文件注釋

在類庫項(xiàng)目上,右鍵屬性-生成-輸出,勾選XML文檔文件,選擇文檔名以及DLL文件輸出的路徑。如下圖:

三.?打開MSBuild Command Prompt for VS2015生成dll文件

輸入命令如下:

csc /t:library /out:D:\DllPath\MetaDataTest1.dll D:\ComputeDemo.cs

其中:/out:D:\DllPath\MetaDataTest1.dll? ?為生成輸出的DLL路徑和DLL文件

? ? ? ? ? ?D:\ComputeDemo.cs? ?為.cs文件路徑位置

則成功生成MetaDataTest1.dll文件(.dll文件命名要和.xml文件一致

四.?使用另一個項(xiàng)目引用.dll文件

右擊References- Add References – Browers 進(jìn)行添加引用。查看注釋是否存在,如下圖所示:

查看DLL相關(guān)信息,如下圖片所示:

五. 運(yùn)行成功:

原文鏈接:https://blog.csdn.net/poyue8754/article/details/123824959

欄目分類
最近更新