C# 使用Azure Devops API,如何从.xlsx文件创建项目?

C# 使用Azure Devops API,如何从.xlsx文件创建项目?,c#,azure,rest,azure-devops,azure-devops-rest-api,C#,Azure,Rest,Azure Devops,Azure Devops Rest Api,我有一个.xlsx文件,其中包含第一列projectname,第二列description。 我想为创建一个控制台应用程序,使用Azure DevOps Rest API从azureProjects.xlsx文件创建项目。我已经实现了下面的代码,但我不明白如何从.xlsx文件中读取并实现代码。你能帮我个忙吗 using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using

我有一个.xlsx文件,其中包含第一列projectname,第二列description。 我想为创建一个控制台应用程序,使用Azure DevOps Rest API从azureProjects.xlsx文件创建项目。我已经实现了下面的代码,但我不明白如何从.xlsx文件中读取并实现代码。你能帮我个忙吗

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

   namespace WorkItemTest
   {
class AzureAdmin
{
    private readonly Uri uri;
    private readonly string personalAccessToken;

    public AzureAdmin(string orgName, string personalAccessToken)
    {
        this.uri = new Uri("https://dev.azure.com/" + orgName);
        this.personalAccessToken = personalAccessToken;
    }

    public async Task<bool> createProject()
    {

        try
        {
            using (HttpClient client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
                    Convert.ToBase64String(
                        Encoding.ASCII.GetBytes(
                            string.Format("{0}:{1}", "", personalAccessToken))));

                var req = new Root
                {
                    name = "test3",
                    description = "test about smthng",
                    visibility = 0,
                    capabilities = new Capabilities
                    {
                        versioncontrol = new Versioncontrol {sourceControlType = "Git"},
                        processTemplate = new ProcessTemplate
                        {
                            templateTypeId = "b8a3a935-7e91-48b8-a94c-606d37c3e9f2"
                        }
                    }
                };

                var result = await client.PostAsJsonAsync($"{uri}/_apis/projects?api-version=5.1", req); //
                Console.WriteLine(result.StatusCode);
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.ToString());
        }
        return true;
    }

    public class Versioncontrol
    {
        public string sourceControlType { get; set; }
    }

    public class ProcessTemplate
    {
        public string templateTypeId { get; set; }
    }

    public class Capabilities
    {
        public Versioncontrol versioncontrol { get; set; }
        public ProcessTemplate processTemplate { get; set; }
    }

    public class Root
    {
        public string name { get; set; }
        public string description { get; set; }
        public int visibility { get; set; }
        public Capabilities capabilities { get; set; }
    }

 }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Net.Http;
使用System.Net.Http.Header;
使用系统文本;
使用System.Threading.Tasks;
名称空间工作项测试
{
AzureAdmin类
{
私有只读Uri;
私有只读字符串personalAccessToken;
public AzureAdmin(字符串orgName、字符串personalAccessToken)
{
this.uri=新uri(“https://dev.azure.com/“+组织名称);
this.personalAccessToken=personalAccessToken;
}
公共异步任务createProject()
{
尝试
{
使用(HttpClient=new HttpClient())
{
client.DefaultRequestHeaders.Accept.Add(新的MediaTypeWithQualityHeaderValue(“应用程序/json”);
client.DefaultRequestHeaders.Authorization=新的AuthenticationHeaderValue(“基本”,
Convert.tobase64字符串(
Encoding.ASCII.GetBytes(
格式(“{0}:{1},”,personalAccessToken));
var req=新根
{
name=“test3”,
description=“关于smthng的测试”,
可见性=0,
能力=新能力
{
versioncontrol=newversioncontrol{sourceControlType=“Git”},
processTemplate=新的processTemplate
{
templateTypeId=“b8a3a935-7e91-48b8-a94c-606d37c3e9f2”
}
}
};
var result=wait client.PostAsJsonAsync($“{uri}/_api/projects?api version=5.1”,req)//
Console.WriteLine(结果状态码);
}
}
捕获(例外情况除外)
{
Console.WriteLine(例如ToString());
}
返回true;
}
公共类版本控制
{
公共字符串sourceControlType{get;set;}
}
公共类ProcessTemplate
{
公共字符串templateTypeId{get;set;}
}
公共类功能
{
公共版本控制版本控制{get;set;}
公共进程模板进程模板{get;set;}
}
公共类根
{
公共字符串名称{get;set;}
公共字符串说明{get;set;}
公共int可见性{get;set;}
公共功能{get;set;}
}
}
}

您已经实现了如何在DevOps中创建团队项目,您需要的是从.xlsx文件中读取项目名称。这不是通过Azure Devops API实现的,您只需要从Excel端获得帮助,以了解如何通过API从.xlsx文件读取数据

检查以下链接以查看它是否有助于您: