简体   繁体   English

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

[英]Using Azure Devops API, how to I create projects from .xlsx file?

I have a .xlsx file, which contains the first column projectname, second column description.我有一个 .xlsx 文件,其中包含第一列项目名称、第二列描述。 I want to create a console app for create projects from azureProjects.xlsx file using Azure DevOps Rest API .我想创建一个控制台应用程序,用于使用 Azure DevOps Rest API 从 azureProjects.xlsx 文件创建项目 I already implement the code below, but I can't understand how to read from .xlsx file and implement the code.我已经实现了下面的代码,但我无法理解如何从 .xlsx 文件中读取并实现代码。 Can you have a solution to help me?你能有一个解决方案来帮助我吗?

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; }
    }

 }
}

You have implemented how to create a team project in DevOps, what you need is reading the project names from .xlsx file.您已经实现了如何在 DevOps 中创建团队项目,您需要从 .xlsx 文件中读取项目名称。 This is not implemented via Azure Devops API, you just need to get help from Excel side to get how to read data from .xlsx file via api.这不是通过 Azure Devops API 实现的,您只需要从 Excel 端获取帮助,以了解如何通过 api 从 .xlsx 文件中读取数据。

Check the following link to see whether it helps you:检查以下链接,看看它是否对您有帮助:

https://docs.microsoft.com/en-us/troubleshoot/dotnet/csharp/query-excel-data-aspx-page https://docs.microsoft.com/en-us/troubleshoot/dotnet/csharp/query-excel-data-aspx-page

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM