1

我正在按照指南将 Visual Studio 中的输出数据写入谷歌电子表格。我将 NUnit 项目类型用于测试自动化目的。

在指南的最后有一个代码块,我粘贴在我的项目中:

using OpenQA.Selenium.Support.UI;
using System;
using NUnit.Framework;
using OpenQA.Selenium;
using System.Collections;
using System.Collections.Generic;
using Google.Apis.Sheets.v4;
using Google.Apis.Auth.OAuth2;
using System.IO;
using Google.Apis.Services;
using Newtonsoft.Json;
using WikipediaTests.Foundation_Class;

namespace AutomationProjects
{
    [TestFixture]
    public class TestClass : TestFoundation
    {
        public class SpreadSheetConnector
        {
        //Codeblock from guide pasted here!
        }
        [Test]
        public void test1()
        {
         //Test case 1. Do XYZ...
        }
    }
}

指南中包含的代码块中,有一段读取 JSON 凭证文件:

private void ConnectToGoogle()
{
    GoogleCredential credential;                
    using (var stream = new FileStream(Path.Combine(HttpRuntime.BinDirectory, "Export Project-03e8aa07234e.json"),
        FileMode.Open, FileAccess.Read))
    {
        credential = GoogleCredential.FromStream(stream).CreateScoped(_scopes);
    }

    //...

但我得到一个错误的“HttpRuntime”说:Error CS0103 The name 'HttpRuntime' does not exist in the current context

VS 没有建议添加新的“使用”引用,所以我假设这不是问题。

那么可能是什么问题呢?从以下到整个代码块:指南

4

1 回答 1

1

简短的回答 - 是的。

长答案 - 我相信您需要在System.Web此处添加 dll。默认情况下,C# 项目不会添加所有依赖项 - 相反,它们会为您提供潜在引用列表,并让用户根据需要进行选择。

在您的项目下,找到该Dependencies部分。右键单击,然后单击Add Reference。在 下Assemblies,找到System.Web并选中它旁边的框,然后单击确定。

添加后,您将需要添加using System.Web到文件的顶部。

本指南也可能有所帮助:https ://docs.microsoft.com/en-us/visualstudio/ide/how-to-add-or-remove-references-by-using-the-reference-manager?view=vs- 2019

于 2019-10-02T15:29:43.210 回答