Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual studio 2015 使用Microsoft Build Tools 2015在TeamCity上编译错误,但不在Visual Studio 2015中编译错误_Visual Studio 2015_C# 6.0_Teamcity 9.0 - Fatal编程技术网

Visual studio 2015 使用Microsoft Build Tools 2015在TeamCity上编译错误,但不在Visual Studio 2015中编译错误

Visual studio 2015 使用Microsoft Build Tools 2015在TeamCity上编译错误,但不在Visual Studio 2015中编译错误,visual-studio-2015,c#-6.0,teamcity-9.0,Visual Studio 2015,C# 6.0,Teamcity 9.0,按照升级解决方案以支持新的C语言功能的说明,我将TeamCity构建步骤的MsBuild Version选项从Microsoft.NET 4.5更改为Microsoft构建工具2015。我可以在Visual Studio 2015中很好地构建解决方案,但我的Teamcity构建失败如下: cs(323,72):错误CS0407:“void Class.Foo()”的返回类型错误 Class.cs的第323行如下所示: LogHelper.WithErrorLogging(this.log

按照升级解决方案以支持新的C语言功能的说明,我将TeamCity构建步骤的
MsBuild Version
选项从
Microsoft.NET 4.5
更改为
Microsoft构建工具2015
。我可以在Visual Studio 2015中很好地构建解决方案,但我的Teamcity构建失败如下:

cs(323,72):错误CS0407:“void Class.Foo()”的返回类型错误

Class.cs的第323行如下所示:

    LogHelper.WithErrorLogging(this.log, "Foo", false, this.Foo, true);
Class.Foo()具有以下签名:

    private void Foo()
LogHelper.WithErrorLogging()有几个重载,但我要调用的重载是:

    public static void WithErrorLogging(ILogger log, string name, bool shouldThrow, Action action, bool logOnlyOnError = false)
正如我所说,构建在Visual Studio 2015中本地成功,但在TeamCity上失败,但如果我删除LogHelper.WithErrorLogging()的此重载,那么TeamCity构建将再次工作:

    public static T WithErrorLogging<T>(ILogger log, string name, bool shouldThrow, Func<T> action, T errorValue = default(T), bool logOnlyOnError = false)
public static T-logging(ILogger日志、字符串名称、bool-shouldtrow、Func-action、T-errorValue=default(T)、bool-logOnlyOnError=false)
我的结论是,Microsoft Build Tools 2015编译器将最后的
true
参数作为第二个重载的
errorValue
参数,从而错误地解决了要调用的重载问题,因此,推断泛型类型参数
T
bool
,最终无法编译,因为
this.Foo()
是一个
操作,而不是
Func
,但从未考虑将第一个重载作为可能的有效调用方法


有人能解释为什么会这样吗?这是一个编译器错误,还是这段代码不应该编译为C#6有正当理由?

完全无关,我建议在代码中使用
nameof(Foo)
而不是硬编码字符串
“Foo”
。这使得代码在重构时更加灵活。谢谢Mafii-我认为这是C#6的一个特性,所以一旦我解决了这个问题,我肯定会这么做:)