因此,我正在考虑在部署过程中作为步骤的一部分添加C#stand alone script,但是really很难找到一个参考,该参考显示了如何正确地“格式化”脚本以用于由章鱼使用。
我确实发现的一件事是,所有引用都必须明确。因此,例如,如果脚本使用HttpClient
发出GET请求,则您不能依赖using
语句来缩短引用,而必须使用“完全限定的名称空间”。
因此基本上不能做到这一点:HttpClient client = new HttpClient();
您必须这样做:System.Net.Http.HttpClient client = new System.Net.HttpClient()
好的,所以我修改了脚本,以明确引用其给定名称空间中的任何类或方法。
现在,如果我有一个自定义课程,会发生什么?我该如何处理?我将通过一个例子来说明我的意思。说我有以下内容:
using System;
namespace MyOctoScript
{
class Person
{
public string name { get; set; }
}
class Script
{
static System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
static System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
public const string endpoint = "some_valid_endpoint";
static async System.Threading.Tasks.Task Main(string [] args)
{
MyOctoScript.Person person = null;
// Use Http Client to fetch JSON from a given endpoint
System.Net.Http.HttpResponseMessage response = await client.GetAsync(endpoint);
// Parse JSON from response
string jsonString = await response.Content.ReadAsStringAsync();
// Store object in variable of type Person
person = serializer.Deserialize<MyOctoScript.Person>(jsonString);
}
}
}
现在,此脚本可用作控制台应用程序。我想确保将它添加为作为Step一部分的C#脚本后能够正常使用。
为了实现此目的,我需要对上面的代码进行哪些更改(如果有的话?)>
提前感谢任何人!
因此,我正在考虑在部署过程中作为步骤的一部分添加C#独立脚本,但是要找到一个参考来展示如何正确“格式化”脚本的方式确实非常困难。 >