VS2015构建项目没有错误,CSC有错误CS1545

时间:2016-11-02 22:36:06

标签: visual-studio-2015 csc

我有一个c#控制台应用程序,用于侦听NetworkInformation.NetworkStatusChanged事件:

using System;  
using Windows.Networking.Connectivity;  

namespace NetworkingConnectivityTest  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            try  
            {  
                NetworkInformation.NetworkStatusChanged += NetworkInformation_NetworkStatusChanged;  

                Console.WriteLine("Press any key to exit...");  
                Console.ReadKey();  

                NetworkInformation.NetworkStatusChanged -= NetworkInformation_NetworkStatusChanged;  
            }  
            catch ( SystemException e )  
            {  
                Console.WriteLine( "Main() exception: " + e.Message );  
            }  
        }  

        private static void NetworkInformation_NetworkStatusChanged( object sender )  
        {  
            try  
            {  
                ConnectionProfile inetCp = NetworkInformation.GetInternetConnectionProfile();  
                Console.WriteLine( "network information changed - internet connection profile: " + inetCp.ProfileName );  
            }  
            catch ( SystemException e )  
            {  
                Console.WriteLine( "NetworkInformation_NetworkStatusChanged exception: " + e.Message );  
            }  
        }  
    }  
}  

当我在VS2015(调试或发布)中构建它时,代码构建并按预期运行。

当我用VS2015开发工具命令提示符构建时,如下所示:
csc / nologo / noconfig / warn:4 .. \ program.cs ^
    / r:" C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETFramework \ v4.5.2 \ System.dll" ^
    / r:" C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETFramework \ v4.5.2 \ mscorlib.dll" ^
    / r:" C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETCore \ v4.5.1 \ System.Runtime.WindowsRuntime.dll" ^
    / r:" C:\ Program Files(x86)\ Windows Kits \ 8.1 \ References \ CommonConfiguration \ Neutral \ Windows.winmd"

我收到以下2条错误消息:
f:\ test \ networkingConnectivityTest \ program.cs(12,36):错误CS1545:属性,索引器或事件' NetworkInformation.NetworkStatusChanged'语言不支持;尝试直接调用访问器方法' NetworkInformation.add_NetworkStatusChanged(NetworkStatusChangedEventHandler)'或者' NetworkInformation.remove_NetworkStatusChanged(EventRegistrationToken)'
f:\ test \ networkingConnectivityTest \ program.cs(17,36):错误CS1545:属性,索引器或事件' NetworkInformation.NetworkStatusChanged'语言不支持;尝试直接调用访问器方法' NetworkInformation.add_NetworkStatusChanged(NetworkStatusChangedEventHandler)'或者' NetworkInformation.remove_NetworkStatusChanged(EventRegistrationToken)'

任何帮助都非常感谢 - 提前感谢。

0 个答案:

没有答案
相关问题