如何以编程方式将 NewLines 添加到 TFS 工作项文本框?
我有一个 Web 系统,它与我们的 TFS 工作项系统有一些挂钩。我想做的一件事是,当执行某个操作时,它会在一个字段中获取当前文本,并在“一般注释”字段中发表评论,宣布该字段之前的内容(是的,我知道,历史包含但上级希望在 gen 评论中看到这一点)。
我遇到的问题是 TFS 似乎忽略了我的字符串中的 Environment.NewLines 。因此,使用以下代码:
item.Fields[GENCOMMENTS].Value = string.Concat(DateTime.Now.ToShortDateString()
, " - QA Dashboard - Required By Date Reason set to \"Hotfix\", but previously contained \""
, item.Fields[REQBYDTREASON].Value.ToString()
, "\"."
, Environment.NewLine
, Environment.NewLine
, Environment.NewLine
, item.Fields[GENCOMMENTS].Value.ToString());
假设我的一般注释部分包含:
THIS SENTENCE WAS ALREADY IN GENERAL COMMENTS
保存工作项时,我在一般注释部分中得到以下输出
9/29/2010 - QA Dashboard - Required By Date Reason set to "Hotfix", but previously contained "hotfixtest".THIS SENTENCE WAS ALREADY IN GENERAL COMMENTS
为什么它会忽略新行以及如何在工作项中添加新行?
谢谢,
I have a web system that has a few hooks into our TFS work item system. One of the things I am trying to do is that when a certain action is performed, it takes the current text in one field and makes a comment in the "General Comments" field announcing what the field was previously (Yes I know, history contains this but the higher ups want this in the gen comments).
The problem I am having is that TFS seems to be ignoring Environment.NewLines that I have in my string. So with this code:
item.Fields[GENCOMMENTS].Value = string.Concat(DateTime.Now.ToShortDateString()
, " - QA Dashboard - Required By Date Reason set to \"Hotfix\", but previously contained \""
, item.Fields[REQBYDTREASON].Value.ToString()
, "\"."
, Environment.NewLine
, Environment.NewLine
, Environment.NewLine
, item.Fields[GENCOMMENTS].Value.ToString());
So assuming my general comments section contains:
THIS SENTENCE WAS ALREADY IN GENERAL COMMENTS
I get the following output in the general comments section when the work item is saved
9/29/2010 - QA Dashboard - Required By Date Reason set to "Hotfix", but previously contained "hotfixtest".THIS SENTENCE WAS ALREADY IN GENERAL COMMENTS
Why is it ignoring the new lines and how can I get a new line into the work item?
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
TFS 工作项内容通常作为 HTML 进行处理。这很可能发生在这里,因此它忽略了文本中无关的换行符。尝试将内容包装在
TFS work item content is often processed as HTML. That's likely happening here and hence it's ignoring the extraneous newlines in the text. Try wrapping the content in a
<pre>
block or using<p>
and see if that fixes the issue.RTF 或 HTMl 控件将使用并呈现 html 标记 - 因此取决于控件。尝试向多行控件添加和格式化富文本,然后在控制台应用程序中对其进行调试 - 浏览字段值 - 您将看到 html 标记。
RTF or HTMl controls will use and render html markup - so depends on the control. Try adding and formatting rich text to a multiline control and then debug it in a console app - browse the field value - you'll see html tags.