我试图以.NET 4.6为目标,并通过将C#语言版本更改为6来利用最新的C#版本.
但是在编译期间我遇到了这个错误:
错误无效选项'6'表示/ langversion; 必须是ISO-1,ISO-2,3,4,5或默认值
如果我将/langversion:6
Web.Config设置更新为5它可以工作,
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701">
Run Code Online (Sandbox Code Playgroud)
但是如何在不使用低语言版本的情况下解决这个问题呢?
我正在使用Visual Studio 2015社区版,我还手动安装了.NET Framework 4.6,以防Visual Studio 2015默认安装它.
该项目是Visual Studio 2015创建的标准ASP.NET MVC模板项目.
Visual Studio Enterprise 16.3.7
在两台单独的机器上使用时,一台机器构建良好,另一台机器抛出错误:
功能“使用声明”在 C# 7.3 中不可用。请使用 8.0 或更高版本的语言。
这可以通过按照此处的建议设置LangVersion
在非工作机器上轻松解决/sf/answers/3365990281/或让 Visual Studio 像上面的打印屏幕一样自动修复它。.csproj
<LangVersion>8.0</LangVersion>
Run Code Online (Sandbox Code Playgroud)
我不明白的是为什么一台机器在没有这条线的情况下可以很好地构建而.csproj
另一台机器需要它?
.NET 4.6引入了AsyncLocal<T>
用于沿异步控制流流动环境数据的类.我以前用过CallContext.LogicalGet/SetData
这个目的,我想知道两者在语义上是否以及以何种方式不同(除了明显的API差异,如强类型和缺乏对字符串键的依赖).
我正在尝试为我的项目和设置中设置4.6 .NET框架,因为它没有列出,我选择了最后一个选项 - 安装更多框架.这导致我进入一个页面,我选择了VS2013,点击了.NET 4.6并下载了软件但是尽管安装成功并重新启动了计算机,我仍然无法在可用选项列表中看到4.6 .NET .
我已经google了一下,发现提到 4.6在Win 8.1(这是我的系统)上可用.然而,它没有明确表示它可用于VS 2013(尽管如此,它并没有说它不是.)
据说.NET 4.1 包含在VS 2015中,但我不清楚它是否适用于VS 2013.是吗?以及如何让它发挥作用?
在安装了TP(又名Targeting Pack)后,我仍然没有在选项中获得任何新内容,如图所示.建议?
到目前为止,我可以使用命令行构建.NET 4.5.2
c:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild MySolution.sln
Run Code Online (Sandbox Code Playgroud)
我需要在计算机上安装的唯一内容是.NET Framework和Visual Studio 2010 shell.
现在我考虑升级到.NET 4.6.但是我找不到如何在没有Visual Studio的情况下构建解决方案的方法.
我不想安装Visual Studio 2015,因为它对于这个托管的虚拟机来说太大了.我希望一些MSBuild或Microsoft软件包安装就足够了.
在浏览PinnableObjectCache
from 的代码时mscorlib
,我遇到了以下代码:
for (int i = 0; i < m_restockSize; i++)
{
// Make a new buffer.
object newBuffer = m_factory();
// Create space between the objects. We do this because otherwise it forms
// a single plug (group of objects) and the GC pins the entire plug making
// them NOT move to Gen1 and Gen2. By putting space between them
// we ensure that object get a chance to move independently (even if some …
Run Code Online (Sandbox Code Playgroud) 在最近升级到.net 4.6之后,我们发现了一个RyuJit产生错误结果的错误,我们现在可以通过在app.config中添加useLegacyJit enabled ="true"来解决这个问题.
如何调试以下生成的机器代码?
我在VS 2015 RTM中创建了一个新的控制台项目,设置为Release,Any CPU,未经检查的Prefer 32 bit,带有和不带调试器的运行产生相同的结果.
using System;
using System.Runtime.CompilerServices;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Calculate());
Console.WriteLine(Calculate());
Console.ReadLine();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Value Calculate()
{
bool? _0 = (bool?)null;
bool? _1 = (bool?)true;
if (!Value.IsPresent<bool>(_1))
{
return default(Value);
}
bool? result = null;
result = (_1.Value ? new bool?(false) : result);
if (_0.HasValue && _0.Value)
{
}
return new Value(result);
}
public struct Value
{
bool? _value;
public Value(bool? …
Run Code Online (Sandbox Code Playgroud) 我们使用TFS 2013作为构建服务器.我已经开始了一个C#6.0项目,我正在努力建立它.我正在使用新的null条件运算符和我的构建chokes.我已经尝试在TFS服务器上安装了几个东西,包括目标包和VS 2015.我已经尝试将/tv:14.0提供给MSBuild参数.
Configuration\EntityEntityConfig.cs(270):无效的表达式术语'.'
Configuration\EntityEntityConfig.cs(283):无效的表达式术语'.'
Configuration\EntityEntityConfig.cs(283):语法错误,':'预期
......等
在这一点上,我不知道还有什么可以尝试.任何建议将不胜感激.
我有一些代码可以在我自己的R-like C#DataFrame类中处理数百万个数据行.有许多Parallel.ForEach调用并行迭代数据行.这段代码使用VS2013和.NET 4.5运行了一年多没有问题.
我有两台开发机器(A和B),最近升级了机器A到VS2015.大约一半时间我开始注意到我的代码中出现了一个奇怪的间歇性冻结.让它运行很长一段时间,事实证明代码最终会完成.它只需要15-120分钟而不是1-2分钟.
使用VS2015调试器尝试全部中断由于某种原因而失败.所以我插入了一堆日志语句.事实证明,在Parallel.ForEach循环期间存在Gen2集合时会发生此冻结(比较每个Parallel.ForEach循环之前和之后的集合计数).整个额外的13-118分钟用于任何Parallel.ForEach循环调用恰好与Gen2集合(如果有的话)重叠.如果在任何Parallel.ForEach循环期间没有Gen2集合(大约50%的时间运行它),那么一切都会在1-2分钟内完成.
当我在机器A上的VS2013中运行相同的代码时,我得到了相同的冻结.当我在机器B(从未升级过)的VS2013中运行代码时,它运行得很好.它一夜之间没有结冰了几十次.
我注意到/试过的一些事情:
我根本没有改变默认的GC设置.根据GCSettings,所有运行都发生在LatencyMode Interactive和IsServerGC为假.
我可以在每次调用Parallel.ForEach之前切换到LowLatency,但我真的更愿意了解正在发生的事情.
在VS2015升级之后,有没有其他人在Parallel.ForEach中看到过奇怪的冻结?关于下一步会有什么好处的任何想法?
更新1:在上面的模糊解释中添加一些示例代码...
以下是一些示例代码,我希望能够证明这个问题.此代码在B机器上运行10-12秒,始终如一.它遇到了许多Gen2系列,但它们几乎没有时间.如果我取消注释两个GC设置行,我可以强制它没有Gen2集合.它比30-50秒慢一些.
现在在我的A机器上,代码需要一段随机的时间.似乎是5到30分钟.它似乎变得更糟,它遇到的Gen2系列越多.如果我取消注释两个GC设置行,则机器A也需要30-50秒(与机器B相同).
可能需要对行数和数组大小进行一些调整才能显示在另一台机器上.
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using System.Linq;
using System.Runtime;
public class MyDataRow
{
public int Id { get; set; }
public double Value { get; set; }
public double DerivedValuesSum { get; set; }
public double[] DerivedValues { get; set; }
}
class Program
{
static void Example()
{
const …
Run Code Online (Sandbox Code Playgroud) c# garbage-collection parallel.foreach visual-studio-2015 .net-4.6
我有以下代码合同:
public void F(string x)
{
Contract.Requires(!string.IsNullOrWhiteSpace(x));
throw new NotImplementedException();
}
Run Code Online (Sandbox Code Playgroud)
编译时,我收到以下警告:
警告CC1036:在方法合同中检测到方法'System.String.IsNullOrWhiteSpace(System.String)'没有[Pure]的调用[...]
怎么处理呢?
奇怪的是,我也在使用string.IsNullOrEmpty
,[Pure]
其他合同中没有标记,并且重写者没有问题.
我的合同重写版的版本是1.9.10714.2.
这是String
我正在使用的类(从元数据中检索)的实现的相关部分:
#region Assembly mscorlib.dll, v4.0.0.0
// C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\mscorlib.dll
#endregion
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Reflection;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
namespace System
{
// Summary:
// Represents text as a series of Unicode characters.To browse the .NET Framework
// source code for this type, see the Reference Source.
[Serializable]
[ComVisible(true)]
public …
Run Code Online (Sandbox Code Playgroud)