项目使用 Visual Studio 构建良好,但从命令行失败

Project builds fine with Visual Studio but fails from the command line(项目使用 Visual Studio 构建良好,但从命令行失败)
本文介绍了项目使用 Visual Studio 构建良好,但从命令行失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个解决方案,在通过 Visual Studio 2015 运行时构建良好,但是当我从命令行运行时遇到错误

I have a solution which builds fine when running through Visual Studio 2015 but when I run from the command line I run into the error

错误 CS1056:此行出现意外字符$"

error CS1056: Unexpected character '$' on this line

var CutOffTextFragment = deadLineTime.Deadline.Minute == 0 ? $"{deadLineTime.Deadline:htt}" : $"{deadLineTime.Deadline:h:mmtt}"

deadLineTime.Deadline 是一个 DateTime 对象,代码将返回 XAM/PM 或 X:XXAM/PM

deadLineTime.Deadline is a DateTime object, the code will return either XAM/PM or X:XXAM/PM

我认为这是因为构建脚本没有使用 C#6.目前此脚本无法更改为使用 c# 6

I think this is occuring becuase the build script is not using C#6. At present this script cant be changed to use c# 6

如果是这种情况,任何人都可以帮我贬低代码以便它与 C# 5 一起使用

If this is the case, can anyone help me depreciate the code so it works with C# 5

推荐答案

$可以转换成string.format.

$ can be converted to string.format.

var CutOffTextFragment = deadLineTime.Deadline.Minute == 0 
                         ? 
                         string.Format("{0:htt}",deadLineTime.Deadline) 
                         : 
                         string.Format("{0:h:mmtt}", deadLineTime.Deadline);

这篇关于项目使用 Visual Studio 构建良好,但从命令行失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

MSBuild cannot find a reference(MSBuild 找不到参考)
The reference assemblies for framework .NETCore, Version=v5.0 were not found(未找到框架 .NETCore,Version=v5.0 的参考程序集)
quot;File has a different computed hash than specified in manifestquot; error when signing the EXE(“文件的计算哈希值与清单中指定的不同签署EXE时出错)
Good-practices: How to reuse .csproj and .sln files to create your MSBuild script for CI?(良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 MSBuild 脚本?)
Run an MSBuild target only if project is actually built(仅在实际构建项目时运行 MSBuild 目标)
MS-Build BeforeBuild not firing(MS-Build BeforeBuild 未触发)