字符串插值将不会建立在TeamCity上 [英] String Interpolation will not build on TeamCity

查看:62
本文介绍了字符串插值将不会建立在TeamCity上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我支持的一个旧项目,我一直在进行一些现代化.其中包括很多事情:将.NET Framework升级到4.6,以及进行其他升级. 还有一些要做的事情,就是在不更改业务逻辑的情况下进行语法升级.

For an old project I support, I've been performing some modernization. That has included various things: bumping the .NET Framework up to 4.6, and other upgrades. One of the things we have some leeway to do is make syntactic upgrades, provided we don't change business logic.

我们最近还安装了Visual Studio 2015,以及最新最出色的ReSharper,它揭示了"String Interpolation"现在可以在我们的代码中完成.对于那些不知道的人,字符串内插是string.Format调用上的语法糖,如下所示:

We've also recently installed Visual Studio 2015, and the latest and greatest ReSharper, which revealed that "String Interpolation" is now something we can do in our code. For those who don't know, string interpolation is syntactic sugar over string.Format calls as below:

// Normal, pre-C#6 formatting:
var foo = string.Format("Some string {0}", bar);

// C#6 String Interpolation
var foo = $"Some string {bar}";

这真的很有用,因为它使消息更易于阅读,并且通常占用更少的字符.

This is really useful because it makes the messages a lot easier to read, and usually by taking up fewer characters.

...但是,TeamCity似乎不同意.当我在提交中上推代码时,出现以下错误:

...Yet, TeamCity seems to disagree. When I pushed the code up in a commit, I got the following error:

Directory\SomeFile.cs: error CS1056: Unexpected character '$' [C:\ProjectDirectory\Project.Core\Project.Core.csproj]

表面上看来,某种C#6之前的构建器正在受到冲击,因为这是C#6的新功能.

On the surface, it seems like a pre-C#6 builder of some sort is being hit, because this is a new feature to C#6.

这就是我所观察到的,这就是为什么我认为这是正在发生的事情的原因:

Here's what I have observed that is why I theorize that this is what's going on:

  1. 构建配置指向C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe,这使我暂停了,因为大概是在我们的构建代理上安装了.NET 4.6.

  1. The build configuration is pointing to C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe This gives me pause, because presumably .NET 4.6 is installed on our build agent.

但是,在尝试从Microsoft安装程序直接安装.NET 4.6时,它失败了,因为在bulid代理上已经安装了.NET 4.6.

Upon trying to directly install .NET 4.6 from the Microsoft installer, though, it fails because .NET 4.6 is already installed on the bulid agent.

我们的构建配置的编译步骤也使我暂停.前两行分别指出了Build Engine和框架的版本是[exec] Microsoft (R) Build Engine version 4.6.1055.0 [exec] [Microsoft .NET Framework, version 4.0.30319.42000].显然,构建引擎是v4.6,但是.NET框架是4.0!我没看错吗?

Our build configuration's compile step is giving me pause as well. The first two lines that note the version of the Build Engine and framework respectively are [exec] Microsoft (R) Build Engine version 4.6.1055.0 [exec] [Microsoft .NET Framework, version 4.0.30319.42000] The build engine is apparently v4.6, but the .NET framework is 4.0!? Am I reading that right?

最后,构建日志的最后几行之一:[NAnt output] External Program Failed: C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe (return code was 1)那不是 4.6 ...是吗?

Lastly, one of the final lines of the build log: [NAnt output] External Program Failed: C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe (return code was 1) That is not 4.6...is it?

问题:双重.第一个问题可能很愚蠢,但是我实际上是针对.NET 4.6编译的吗?其次,如果我指向,我可以通过什么方式在C#6中真正构建String Interpolation语法. NET 4.6?

Question: Twofold. This first question might be stupid, but am I actually compiling against .NET 4.6? Secondly, in what way can I get the String Interpolation syntax in C#6 to actually build, if I am pointing to .NET 4.6?

我显然在所有这些方面都缺少了某物,我不确定A)我缺少了多少东西,或者B)我应该怎么做.

I'm clearly missing something about all of this, I'm not sure A) how many things I'm missing, or B) what exactly I should do about them.

推荐答案

我为自己辩护;有趣的路径/版本实际上表明了真正的问题:正在运行的MSBuild.exe不是VS2015安装的版本.

I feel vindicated; the funny path/version was in fact indicative of the true problem: the MSBuild.exe that was being ran was not the one installed by VS2015.

当我从此处阅读 时,在C:\Windows\Microsoft.NET\Framework\v4.0.30319中找到的MSBuild.exe版本实际上是C#6之前的版本;由于某些原因,安装Visual Studio 2015不会不会更改安装!

As I read from here, the version of MSBuild.exe that is found in C:\Windows\Microsoft.NET\Framework\v4.0.30319 is actually a pre-C#6 version; for some reason, installing Visual Studio 2015 does not alter that installation!

相反,您应该将MSBuild.exe调用指向存储在C:\Program Files (x86)\MSBuild\14.0\Bin的副本,以针对VS2015安装的最新C#版本进行编译.

Instead you should point your MSBuild.exe call to the copy stored at C:\Program Files (x86)\MSBuild\14.0\Bin to be compiling against the latest C# version, as installed by VS2015.

这篇关于字符串插值将不会建立在TeamCity上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆