有一个类似的问题here,但我认为这涉及不同的原因。
我将一个班级从一个较新的项目转移到一个较旧的项目中。两者都针对.net 4.6但是在移动之后我在构建时收到了以下错误。
功能'插值字符串'在C#5中不可用。请使用语言版本6或更高版本。
我尝试将项目设置为在属性窗口中使用C#6进行构建而不做任何更改。
答案 0 :(得分:17)
答案 1 :(得分:9)
安装DotNetCompilerPlatform版本2.1.0
答案 2 :(得分:1)
将此添加到您的web.config。安装DotNetCompilerPlatform后,它可能会自动添加。
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" />
</compilers>
</system.codedom>
答案 3 :(得分:0)
(它可以轻松适用于VS 2019-.NET Framework 4.8 Web应用程序项目)
在安装DotNetCompilerPlatform v3.6之后我已经意识到了这个问题
我一直在寻找TheColonel26的答案,但无法更改所选的语言版本:
显然,我们不能更改所选语言的版本。 (For details look here)
此后,我使用了kfwbird的答案,但对较新版本进行了更改:
using System;
using Xamarin.Forms.Platform.iOS;
using Foundation;
using UIKit;
using Xamarin.Forms;
using CoreGraphics;
using EficienciaEnergetica.iOS.KeyboardOverlap;
using System.Diagnostics;
using EficienciaEnergetica.ContentPages;
[assembly: ExportRenderer(typeof(Page), typeof(KeyboardOverlapRenderer))]
namespace EficienciaEnergetica.iOS.KeyboardOverlap
{
[Preserve(AllMembers = true)]
public class KeyboardOverlapRenderer : PageRenderer
{
Rectangle initialViewState;
NSObject _keyboardShowObserver;
NSObject _keyboardHideObserver;
private bool _pageWasShiftedUp;
private double _activeViewBottom;
private bool _isKeyboardShown;
public static void StaticInit()
{
var now = DateTime.Now;
Debug.WriteLine("Keyboard Overlap plugin initialized {0}", now);
}
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
var page = Element as ContentPage;
if (page != null)
{
var contentScrollView = page.Content as ScrollView;
if (contentScrollView != null)
return;
initialViewState = Element.Bounds;
RegisterForKeyboardNotifications();
}
}
public override void ViewWillDisappear(bool animated)
{
base.ViewWillDisappear(animated);
UnregisterForKeyboardNotifications();
}
void RegisterForKeyboardNotifications()
{
if (_keyboardShowObserver == null)
_keyboardShowObserver = NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.WillShowNotification, OnKeyboardShow);
if (_keyboardHideObserver == null)
_keyboardHideObserver = NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.WillHideNotification, OnKeyboardHide);
}
void UnregisterForKeyboardNotifications()
{
_isKeyboardShown = false;
if (_keyboardShowObserver != null)
{
NSNotificationCenter.DefaultCenter.RemoveObserver(_keyboardShowObserver);
_keyboardShowObserver.Dispose();
_keyboardShowObserver = null;
}
if (_keyboardHideObserver != null)
{
NSNotificationCenter.DefaultCenter.RemoveObserver(_keyboardHideObserver);
_keyboardHideObserver.Dispose();
_keyboardHideObserver = null;
}
}
protected virtual void OnKeyboardShow(NSNotification notification)
{
if (!IsViewLoaded)
return;
_isKeyboardShown = true;
var activeView = View.FindFirstResponder();
if (activeView == null)
return;
var keyboardFrame = UIKeyboard.FrameEndFromNotification(notification);
var isOverlapping = activeView.IsKeyboardOverlapping(View, keyboardFrame);
if (!isOverlapping)
return;
if (isOverlapping)
{
System.Diagnostics.Debug.WriteLine(keyboardFrame);
_activeViewBottom = activeView.GetViewRelativeBottom(View);
ShiftPageUp(keyboardFrame.Height, _activeViewBottom);
}
}
private void OnKeyboardHide(NSNotification notification)
{
if (!IsViewLoaded)
return;
_isKeyboardShown = false;
var keyboardFrame = UIKeyboard.FrameEndFromNotification(notification);
if (_pageWasShiftedUp)
ShiftPageDown(keyboardFrame.Height, _activeViewBottom);
}
private void ShiftPageUp(nfloat keyboardHeight, double activeViewBottom)
{
var pageFrame = initialViewState;// Element.Bounds;
var newY = pageFrame.Y + CalculateShiftByAmount(pageFrame.Height, keyboardHeight, activeViewBottom);
Element.LayoutTo(new Rectangle(pageFrame.X, newY,
pageFrame.Width, pageFrame.Height));
_pageWasShiftedUp = true;
}
private void ShiftPageDown(nfloat keyboardHeight, double activeViewBottom)
{
Element.LayoutTo(initialViewState);
_pageWasShiftedUp = false;
}
private double CalculateShiftByAmount(double pageHeight, nfloat keyboardHeight, double activeViewBottom)
{
return (pageHeight - activeViewBottom) - keyboardHeight;
}
}
}
现在它可以正常工作了。