2016-03-25 10 views
9

विजुअल स्टूडियो के बिना सी # 6.0 फीचर्स का उपयोग कैसे करें?सी # 6.0 विजुअल स्टूडियो के बिना

निम्नलिखित C# 6.0 Code काम नहीं करता:

>csc CS6.cs 
Microsoft (R) Visual C# Compiler version 4.6.1055.0 
for Microsoft (R) .NET Framework 4.5 
Copyright (C) Microsoft Corporation. All rights reserved. 

CS6.cs(1,7): error CS1041: Identifier expected; 'static' is a keyword 
CS6.cs(1,14): error CS1518: Expected class, delegate, enum, interface, or struct 

यहाँ determine which .NET Framework versions are installed सी # कोड है::

using static System.Console; 

class Program 
{ 
    static void Main() 
    { 
     WriteLine("Hello world!"); 
    } 
} 

यहाँ त्रुटि है

using System; 
using Microsoft.Win32; 

class RegistryVersion 
{ 
    private static void GetVersionFromRegistry() 
    { 
     // Opens the registry key for the .NET Framework entry. 
      using (RegistryKey ndpKey = 
       RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, ""). 
       OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\")) 
      { 
       // As an alternative, if you know the computers you will query are running .NET Framework 4.5 
       // or later, you can use: 
       // using (RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, 
       // RegistryView.Registry32).OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\")) 
      foreach (string versionKeyName in ndpKey.GetSubKeyNames()) 
      { 
       if (versionKeyName.StartsWith("v")) 
       { 

        RegistryKey versionKey = ndpKey.OpenSubKey(versionKeyName); 
        string name = (string)versionKey.GetValue("Version", ""); 
        string sp = versionKey.GetValue("SP", "").ToString(); 
        string install = versionKey.GetValue("Install", "").ToString(); 
        if (install == "") //no install info, must be later. 
         Console.WriteLine(versionKeyName + " " + name); 
        else 
        { 
         if (sp != "" && install == "1") 
         { 
          Console.WriteLine(versionKeyName + " " + name + " SP" + sp); 
         } 

        } 
        if (name != "") 
        { 
         continue; 
        } 
        foreach (string subKeyName in versionKey.GetSubKeyNames()) 
        { 
         RegistryKey subKey = versionKey.OpenSubKey(subKeyName); 
         name = (string)subKey.GetValue("Version", ""); 
         if (name != "") 
          sp = subKey.GetValue("SP", "").ToString(); 
         install = subKey.GetValue("Install", "").ToString(); 
         if (install == "") //no install info, must be later. 
          Console.WriteLine(versionKeyName + " " + name); 
         else 
         { 
          if (sp != "" && install == "1") 
          { 
           Console.WriteLine(" " + subKeyName + " " + name + " SP" + sp); 
          } 
          else if (install == "1") 
          { 
           Console.WriteLine(" " + subKeyName + " " + name); 
          } 
         } 
        } 
       } 
      } 
     } 
    } 

    static void Main() 
    { 
     GetVersionFromRegistry(); 
    } 
} 

यहाँ सी # कोड के लिए उत्पादन है यह निर्धारित करने के लिए कि कौन सी .NET Framework संस्करण स्थापित हैं:

>csc FrameworkVersion.cs 
Microsoft (R) Visual C# Compiler version 4.6.1055.0 
for Microsoft (R) .NET Framework 4.5 
Copyright (C) Microsoft Corporation. All rights reserved. 

>FrameworkVersion.exe 
v2.0.50727 2.0.50727.4927 SP2 
v3.0 3.0.30729.4926 SP2 
v3.5 3.5.30729.4926 SP1 
v4 
    Client 4.6.01055 
    Full 4.6.01055 
v4.0 
    Client 4.0.0.0 

कृपया ध्यान दें कि इस सवाल का किसी भी दृश्य स्टूडियो/आईडीई बिना बारे में सी # 6.0 है।

+0

विज़ुअल स्टूडियो के बिना आप संकलित कैसे करते हैं? क्या आप अपना निर्माण कमांड शामिल कर सकते हैं? –

+0

इस प्रश्न को देखें: http://stackoverflow.com/questions/31875825/how-to-run-roslyn-instead-csc-exe-from-command-line यह शायद वही है। सबसे अधिक संभावना है कि आप csc.exe –

+0

के गलत संस्करण (गलत पथ से) चला रहे हैं कृपया ध्यान दें कि यह कमांड प्रॉम्प्ट और .NET Framework 4.6 (NDP461-KB3102436-x86-x64-AllOS-ENU.exe) का उपयोग कर रहा है और विजुअल स्टूडियो नहीं । – Impavid

उत्तर

4

सी # 6 एक विशिष्ट ढांचे संस्करण की ओर नहीं बनाया गया है, यह सब संकलक पर निर्भर करता है। यदि आप सी # 6 कंपाइलर का उपयोग करते हैं, तो आप उस स्निपेट को संकलित कर सकते हैं।

सुनिश्चित करें कि आपने अपनी बिल्ड मशीन पर नवीनतम MSBuild संस्करण स्थापित किया है (उन्होंने संकलक फ़ोल्डर से संकलक को स्थानांतरित किया है)। उस स्थापना में नवीनतम कंपाइलर है। (यदि आपके प्रोजेक्ट को निम्न ढांचे संस्करण के निर्माण के लिए निर्दिष्ट किया गया है तो नवीनतम फ्रेमवर्क संस्करण चलाने की आवश्यकता नहीं है)

आप NuGet कमांड लाइन का उपयोग कर कंपाइलर NuGet पैकेज भी इंस्टॉल कर सकते हैं।

उपयोगी संसाधन:

3

आपकी समस्या संकलक

>csc CS6.cs 
Microsoft (R) Visual C# Compiler version -->4.6.1055.0<-- 
for Microsoft (R) .NET Framework 4.5 

आप 4.6 संकलक का उपयोग कर रहे हैं जब आप 6 संकलक की जरूरत के साथ है।

सी # 6 संकलक दृश्य स्टूडियो के साथ स्थापित किया गया है, फिर भी लगता है कि किसी को आईडीई की परवाह किए बिना यह स्थापित करने के लिए इन स्थानों से compilers उपयोग करने के लिए

https://social.msdn.microsoft.com/Forums/vstudio/en-US/9959d4c1-16fe-45bc-9535-7b0775d26e9a/please-confirm-c-60-compiler-is-not-installed-with-net-framework-46-if-so-location?forum=csharpgeneral

http://www.microsoft.com/en-us/download/details.aspx?id=48159 Microsoft Build Tools 2015 It says it only depends on .NET Framework 4.5... I guess the Roslyn-based C# 6.0 compiler can target .NET Framework 4.5? What is this thing's relationship to the .NET Framework 4.6 Targeting pack? Will that install this? Or are both needed? And like I said, can I compile using C# 6 language features in VS2013?
2

कोशिश में कामयाब रहे:

%ProgramFiles(x86)%\MSBuild\12.0\Bin\ 
%ProgramFiles(x86)%\MSBuild\12.0\Bin\amd64\ 
%ProgramFiles(x86)%\MSBuild\14.0\Bin\ 
%ProgramFiles(x86)%\MSBuild\14.0\Bin\amd64\ 
संबंधित मुद्दे