首页 > 解决方案 > uri 类未显示在系统命名空间中

问题描述

我正在尝试使用 .NET 4.5 Framework 编译以下代码:

using System;
using System.Collections.Generic;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Discussion.Client;
using Microsoft.TeamFoundation.VersionControl.Client;

class CodeReview
{

    public List<CodeReviewComment> GetCodeReviewComments(int workItemId)
    {
        List<CodeReviewComment> comments = new List<CodeReviewComment>();
        Uri tfsuri = new Uri(MYURL);
        TeamFoundationDiscussionService service = new TeamFoundationDiscussionService();
        service.Initialize(new Microsoft.TeamFoundation.Client.TfsTeamProjectCollection(tfsuri));
        IDiscussionManager discussionManager = service.CreateDiscussionManager();

        IAsyncResult result = discussionManager.BeginQueryByCodeReviewRequest(workItemId, QueryStoreOptions.ServerAndLocal, new AsyncCallback(CallCompletedCallback), null);
        var output = discussionManager.EndQueryByCodeReviewRequest(result);

        foreach (DiscussionThread thread in output)
        {
            if (thread.RootComment != null)
            {
                CodeReviewComment comment = new CodeReviewComment();
                comment.Author = thread.RootComment.Author.DisplayName;
                comment.Comment = thread.RootComment.Content;
                comment.PublishDate = thread.RootComment.PublishedDate.ToShortDateString();
                comment.ItemName = thread.ItemPath;
                comments.Add(comment);
            }
        }

        return comments;
    }

    static void CallCompletedCallback(IAsyncResult result)
    {
        // Handle error conditions here
    }

    public class CodeReviewComment
    {
        public string Author { get; set; }
        public string Comment { get; set; }
        public string PublishDate { get; set; }
        public string ItemName { get; set; }
    }

}

Visual Studio 编译器抱怨“找不到类型或命名空间‘Uri’”,当我在对象浏览器中展开系统命名空间时,它没有列出任何 Uri 类。我已经尝试了其他几个版本的 .NET,但仍然遇到同样的问题,尽管如果我选择 .NET 4.0 客户端配置文件,它确实会出现,但是 Microsoft 命名空间中不存在任何 TeamFoundation 类。

标签: c#.net

解决方案


我解决了自己的问题,但我不明白为什么它会起作用。无奈之下,我使用 .NET 4.5 创建了另一个新项目,然后复制并粘贴了代码。它编译并且 Uri 在对象浏览器中显示为一个类。我不知道这两个项目之间有什么区别。


推荐阅读