3

我无法使用最新 (5/1/2015) 版本的 Visual Studio 2015 RC 14.0.22823.1 D14REL 诊断依赖问题。

以下代码未编译并引发此错误:

Severity    Code    Description Project File    Line
Error   CS1061  
'Thread' does not contain a definition for 'CurrentCulture' and no 
extension method 'CurrentCulture' accepting a first argument of type 
'Thread' could be found (are you missing a using directive or an assembly
reference?) 
ServiceLibrary.DNX Core 5.0 


using System;
using System.Globalization;
using System.Threading;

namespace ServiceLibrary
{
    public class CultureService
    {
        public void SetCulture(string cultureCode = "fr-FR")
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo(cultureCode);
        }
    }
}

将鼠标悬停在 CultureInfo Visual Studio 上会显示一个弹出窗口,其中显示: 在此处输入图像描述

这是project.json

{
  "version": "1.0.0-*",
  "description": "",
  "authors": [ "" ],
  "tags": [ "" ],
  "projectUrl": "",
  "licenseUrl": "",

  "dependencies": {
    "System.Threading": "4.0.10-beta-22816",
    "System.Threading.Thread": "4.0.0-beta-22816",
    "System.Globalization": "4.0.10-beta-22816"
  },

  "frameworks": {
    "dnx451": { },
    "dnxcore50": {
      "dependencies": {
        "System.Collections": "4.0.10-beta-22816",
        "System.Linq": "4.0.0-beta-22816",
        "Microsoft.CSharp": "4.0.0-beta-22816",

      }
    }
  }
}

我希望有人能帮忙看看问题出在哪里。

谢谢

4

1 回答 1

2

文化命名空间位于 DNCCORE50 和成熟的 DNX451 之间的不同位置,因此您必须使用编译器指令。希望这可以帮助。

#if DNX451
            Thread.CurrentThread.CurrentCulture = new CultureInfo(cultureCode);
#elif DNXCORE50
            CultureInfo.CurrentCulture = new CultureInfo(cultureCode);
#else
#error No Implementation for the target DNX 
#endif
于 2015-05-05T21:13:55.350 回答