如何使用csc编译参考System.Net.Http的cs文件?

时间:2018-01-14 13:36:09

标签: c# csc system.net.httpwebrequest

我是C#的新手,我整晚都在尝试编译代码。我不是要求逻辑,而是使用csc编译帮助。

我有一个使用System.Net.Http的应用,我试图使用csc将其编译成可执行文件,但我总是得到以下结果:

C:\Users\farao\Documents\Visual Studio 2017\source\repos\SimpleWebCrawlerApp\SimpleWebCrawlerApp>csc Program.cs
Microsoft (R) Visual C# Compiler version 2.6.0.62329 (5429b35d)
Copyright (C) Microsoft Corporation. All rights reserved.

Program.cs(4,18): error CS0234: The type or namespace name 'Http' does not exist in the namespace 'System.Net' (are you missing an assembly reference?)

C:\Users\farao\Documents\Visual Studio 2017\source\repos\SimpleWebCrawlerApp\SimpleWebCrawlerApp>

但是,我可以在Visual Studio 2017中编译,但我需要使用csc进行编译以便快速分发。

我尝试了几乎所有这些link

using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Collections;
using System.Text.RegularExpressions;

namespace SimpleWebCrawlerApp
{

class Program
{
    internal static int SUCCESS = 0;
    internal static int FAIL = -1;

    static void Main(string[] args)
    {
        TextWriter errorWriter = Console.Error;
        if (args.Length != 2)
        {
            errorWriter.WriteLine("usage: <program_name>.exe <http/https url> <number of hops>");
        }
        else
        {
            if (IsValidUrl(args[0]))
            {
                int hops;
                if (int.TryParse(args[1], out hops))
                {
                    new HTTPCrawler(args[0], hops).Crawl();
                    Environment.Exit(SUCCESS);
                }
                errorWriter.WriteLine("not a valid integer for number of hops");
            }
            else
            {
                errorWriter.WriteLine("observe proper http/https protocol");
            }
        }
        Environment.Exit(FAIL);
    }

1 个答案:

答案 0 :(得分:0)