none
msbuild runs against 'get => ...' property accessor RRS feed

  • Question

  • Hi, Gent's.

    This code

        public class SampleCS1043
        {
            public int Something
            {
                get => 666;
                set { }
            }
            public int Anything { set; get; }
    
            public void Method()
            {
                Something = 3;
                Anything = 42;
                Console.WriteLine("Some is {0}, Any is {1}", Something, Anything);
            }
        }
    

    compiles and runs fine within VS Enterprise 2017.

    But when doing a build by command shell, I get

      SampleCS1043.cs(13,17): error CS1043: { or ; expected 
      SampleCS1043.cs(13,17): error CS1513: } expected 
      SampleCS1043.cs(14,17): error CS1002: ; expected 
      SampleCS1043.cs(15,10): error CS1513: } expected 

    with line 13 being SampleCS1043.Something.get().

    My build command is

    "C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/MSBuild/15.0/Bin"/msbuild.exe Some.csproj /p:Configuration=Debug /p:VisualStudioVersion=14.0 /p:TargetFrameworkVersion=v4.5 /tv:14.0  /l:FileLogger,Microsoft.Build.Engine

    So, my question is: What am I doing wrong? Tools version? Studio version? Framework version? MSBuild version?

    THX in advance

    Mike

    Tuesday, September 26, 2017 11:41 AM

Answers

  • Hi mike.soft,

    Thank you for posting here.

    I test the code you provided. When I build it, it works well. For VS 2017, you should use 15.0.

    "C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/MSBuild/15.0/Bin"/msbuild.exe Some.csproj /p:Configuration=Debug /p:VisualStudioVersion=15.0 /p:TargetFrameworkVersion=v4.5 /tv:15.0

    Here is the code I test in msBuild.exe.

        class Program
        {
            static void Main(string[] args)
            {          
                int s= SampleCS1043.Something;
                SampleCS1043.Method();
                Console.ReadKey();
            }     
        }
        public class SampleCS1043
        {
            public static int Something
            {
                get => 666;
                set { }
            }
            public static int Anything { set; get; }
    
            public static void Method()
            {
                Something = 3;
                Anything = 42;
                Console.WriteLine("Some is {0}, Any is {1}", Something, Anything);
            }
        }

    What is the logger doing for? If I do not use it. It will show the Build succeeded.

    If I use the command below, it will show the build error.

    /l:FileLogger,Microsoft.Build.Engine
    MSBUILD : Logger error MSB4104: Failed to write to log file "msbuild.log". Access to the path 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\msbuild.log' is denied.

    If the logger is helpful to you, I will do the further testing.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Wednesday, September 27, 2017 9:31 AM
    Moderator

All replies

  • hi , 

    use the targetframeworkversion version 4.7 

    c# expression bodied get and set for properties is allowed in c#7.0

    https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7

    kind regards


    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, September 26, 2017 12:26 PM
  • Sorry, no:

    C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1098,5): error MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.7" were not found.

    Tuesday, September 26, 2017 1:00 PM
  • have you already updated your visual studio 2017 with 15.1 or higher? 

    because i remember that this was a bug a while ago. 

    https://developercommunity.visualstudio.com/content/problem/44043/net-framework-47-not-available-on-the-hosted-vs201.html


    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, September 26, 2017 2:22 PM
  • Hi mike.soft,

    Thank you for posting here.

    I test the code you provided. When I build it, it works well. For VS 2017, you should use 15.0.

    "C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/MSBuild/15.0/Bin"/msbuild.exe Some.csproj /p:Configuration=Debug /p:VisualStudioVersion=15.0 /p:TargetFrameworkVersion=v4.5 /tv:15.0

    Here is the code I test in msBuild.exe.

        class Program
        {
            static void Main(string[] args)
            {          
                int s= SampleCS1043.Something;
                SampleCS1043.Method();
                Console.ReadKey();
            }     
        }
        public class SampleCS1043
        {
            public static int Something
            {
                get => 666;
                set { }
            }
            public static int Anything { set; get; }
    
            public static void Method()
            {
                Something = 3;
                Anything = 42;
                Console.WriteLine("Some is {0}, Any is {1}", Something, Anything);
            }
        }

    What is the logger doing for? If I do not use it. It will show the Build succeeded.

    If I use the command below, it will show the build error.

    /l:FileLogger,Microsoft.Build.Engine
    MSBUILD : Logger error MSB4104: Failed to write to log file "msbuild.log". Access to the path 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\msbuild.log' is denied.

    If the logger is helpful to you, I will do the further testing.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Wednesday, September 27, 2017 9:31 AM
    Moderator
  • The 'About' screen says Version 15.3.0.

    Thanks, thow.

    Wednesday, September 27, 2017 3:25 PM
  • That's it, Wendy.

    Thanks a lot!

    Wednesday, September 27, 2017 3:28 PM