在Visual Studio中构建的代码将无法在TFS中生成

我在C#类中定义了两个扩展方法。 当我编译在Visual Studio 2015中使用这些扩展方法的代码时,它们可以正确编译。 当我在本地Team Foundation Build Server上运行相同的代码时,使用MSBuild 2015和/p:VisualStudioVersion=14.0,代码将无法编译。 我需要采取哪些额外步骤来配置构建服务器以便代码编译?

这些是相关的方法签名

public static IEnumerable LeftOuterJoin(this IEnumerable outer, IEnumerable inner, Func outerKeySelector, Func innerKeySelector, Func resultSelector) where TInner : class; public static IEnumerable LeftOuterJoin(this IEnumerable outer, IEnumerable inner, Func outerKeySelector, Func innerKeySelector, Func resultSelector) where TInner : class 

这是构建服务器上的编译错误:

我在C#类中定义了两个扩展方法。 当我编译在Visual Studio 2015中使用这些扩展方法的代码时,它们可以正确编译。 当我在本地Team Foundation Build Server上运行相同的代码时,使用MSBuild 2015和/p:VisualStudioVersion=14.0,代码将无法编译。 我需要采取哪些额外步骤来配置构建服务器以便代码编译?

这些是相关的方法签名

 public static IEnumerable LeftOuterJoin(this IEnumerable outer, IEnumerable inner, Func outerKeySelector, Func innerKeySelector, Func resultSelector) where TInner : class; public static IEnumerable LeftOuterJoin(this IEnumerable outer, IEnumerable inner, Func outerKeySelector, Func innerKeySelector, Func resultSelector) where TInner : struct; 

基于构建服务器中的编译器错误,看起来构建过程接受方法的“where TInner:struct”版本作为合适的重载,即使TInner是引用类型,而我的开发机器上的Visual Studio不是认为这些方法含糊不清。 这是构建服务器上的编译错误:

 The call is ambiguous between the following methods or properties: 'Extensions.LeftOuterJoin(System.Collections.Generic.IEnumerable, System.Collections.Generic.IEnumerable, System.Func, System.Func, System.Func)' and 'Extensions.LeftOuterJoin(System.Collections.Generic.IEnumerable, System.Collections.Generic.IEnumerable, System.Func, System.Func, System.Func)' 

如果您使用的是TFS2015,则必须确保构建计算机上的构建环境与本地开发计算机相同。 您应该在构建计算机上安装VS2015。

如果您使用的是TFS2013或TFS2012,则此/p:VisualStudioVersion=14.0参数不起作用。 您需要自定义tfs构建过程模板,以将Run MSBuild for Project的ToolPath设置为MSBuild14; 并将ToolVersion设置为“14.0”。 检查此BuildActivity是否忽略了用于deatils的ToolsVersion。

我知道这是一个老post,但只是为了扩展一点答案,如果您使用TFS2015,您有两个选项来编译代码,一个使用VisualStudio构建任务,另一个使用MSBuild任务,I建议和第一个一起去。 有时,为了定位MSBuild14,您还有两个选择

1-直接将MSBuild14定位为@ Patrick-MSFT说2 – 而不是1,您可以在名为Microsoft.Net.Compilers的项目中包含Nuget依赖项,在此答案时版本2.0.1是正确的版本获取最新版本的C#编译器作为构建的一部分运行。 另请查看我的答案: https : //stackoverflow.com/a/42931980/819153

但大多数人不喜欢更新同一解决方案上的所有项目来定位nuget包。 您需要在服务器上安装最新版本的Microsoft Tools 2015,而不是这样,您可以从此处下载它.https://www.microsoft.com/en-us/download/details.aspx?id = 48159

根据我的经验,您需要深入了解,代理有能力,一旦您创建代理,它就会发现您的机器的function,它知道您安装的MSBuild的版本,在某些情况下,人们在运行代理后安装MSBuild。 我的建议,停止代理并在安装MSBuild后重新创建它们。 避免TFS服务器出现问题的最安全方法是在那里安装Visual Studio 2015,在重新编写代理之后,所有内容都与最新版本的MSBuild以及最新版本的Visual Studio完美运行。 安装Microsoft Tools 2015并未在TFS上提供最新版本的Visual Studio文件夹。 所以你可以安装它,或者代替那个创建MSBuild任务并传递你需要的所有参数

希望这可以帮助