none
Got some questions about why a C# project isn't compiling using VS 2015, but does using VS 2017 RRS feed

  • Question

  • We're working on a new WPF app. It was started using VS 2015. Recently, when I was working on it I decided to start using VS 2017 instead. (I use VS 2017 at home.) The most important thing here is that I was under the impression that all versions of Visual Studio, would adhere to the rules for C# defined by whatever version of the .NET framework a project is developed under. This project is developed using .NET 4.5.2, using VS 2015. When I started using VS 2017, I did not change the .NET version.

    During the last month of so VS 2017 would inform me that I could optimize code by using certain constructs. For example, there's a property defined SelectedRows. Originally it was defined like this:

    public IList<DATracking> SelectedRows
    {
    	get:
    	{
    		_dataHandler.SelectedRows;
    	}
    	set:
    	{
    		_dataHandler.SelectedRows = value;
    	}
    }
    

    VS 2017 suggested I could use the following instead:

    public IList<DATracking> SelectedRows
    {
    	get => _dataHandler.SelectedRows;
    	set => _dataHandler.SelectedRows = value;
    }
    

    So, I did. And I did other, similar optimizations of code, as I said, under the impression the VS 2017 would adhere to whatever restrictions existed for the .NET framework which is being used by the project.

    Now one of my colleagues started helping me with the project. He got it out of TFS (on premise), did a Get Latest from the solution downward and tried to compile it.

    It failed.

    After a while we realized that it is because he is using VS 2015, whereas I was using VS 2017.

    So, I don't get it. Was I under the wrong impression about Visual Studio all this time? This the C# code optimization that VS 2017 suggested something that's only true of newer versions of the .NET framework? This is no idle topic of us, because at this point our TFS build system will only use, at most, VS 2015. If there's a difference using VS 2017, then I guess at this point we should stop using VS 2017 entirely and only use VS 2015 or older.


    Rod

    Monday, April 2, 2018 3:37 PM

Answers

  • The code you have shown which compiles in VS 2017 is actually using C # 7 Expression Bodied Members feature and in VS 2015 i think we only have support of C# 6 by default. You need to look if you can have C# 7 support in VS 2015 some way or you need to stick to C# 6 if you want your project to be working in VS 2015 too. Just change the MSBuild in for your project in VS 2017 to compile the code in C# 6.

    See the following post for enabling C # 7 in Visual Studio 2015:

    https://stackoverflow.com/a/43048660/1875256


    [If a post helps to resolve your issue, please click the "Mark as Answer" of that post or click Answered"Vote as helpful" button of that post. By marking a post as Answered or Helpful, you help others find the answer faster. ]


    Blog | LinkedIn | Stack Overflow | Facebook
    profile for Ehsan Sajjad on Stack Exchange, a network of free, community-driven Q&A sites



    Monday, April 2, 2018 4:01 PM

All replies

  • The code you have shown which compiles in VS 2017 is actually using C # 7 Expression Bodied Members feature and in VS 2015 i think we only have support of C# 6 by default. You need to look if you can have C# 7 support in VS 2015 some way or you need to stick to C# 6 if you want your project to be working in VS 2015 too. Just change the MSBuild in for your project in VS 2017 to compile the code in C# 6.

    See the following post for enabling C # 7 in Visual Studio 2015:

    https://stackoverflow.com/a/43048660/1875256


    [If a post helps to resolve your issue, please click the "Mark as Answer" of that post or click Answered"Vote as helpful" button of that post. By marking a post as Answered or Helpful, you help others find the answer faster. ]


    Blog | LinkedIn | Stack Overflow | Facebook
    profile for Ehsan Sajjad on Stack Exchange, a network of free, community-driven Q&A sites



    Monday, April 2, 2018 4:01 PM
  • An important point here is that when working with a team, all team members should be using the same version of Visual Studio else problems such as you have currently encountered will occur.

    In regards to TFS/VSTS not working for versions of Visual Studio newer than VS2015, have never heard that before. Our team had members start projects in VS2015 then transitioned to VS2017 together without issues.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Monday, April 2, 2018 4:58 PM
    Moderator
  • Yes very well said, i think in team all should be using the same version, and when we shift from lower to higher version of language or IDE it's fine but moving from higher to low and we end up with issues.

    [If a post helps to resolve your issue, please click the "Mark as Answer" of that post or click Answered "Vote as helpful" button of that post. By marking a post as Answered or Helpful, you help others find the answer faster. ]


    Blog | LinkedIn | Stack Overflow | Facebook
    profile for Ehsan Sajjad on Stack Exchange, a network of free, community-driven Q&A sites

    Monday, April 2, 2018 5:14 PM
  • I'm not following something you said, Karen. Are you saying that it is possible for us to use TFS 2015, to compile an application that's written for VS 2017, without having VS 2017 on the build server? (Just to make it clear, we don't, at this point, have any projects that have been started using VS 2017 that are in TFS. I'm just wondering about that possibility. I thought, given what you said, that it actually might be possible to compile a project for VS 2017 without having VS 2017 around.)

    Rod

    Monday, April 2, 2018 9:25 PM
  • Second quick note. I hear what you're saying about everyone working with the same version of <fill in the blank>. However, in this case I find that working with VS 2017 to be far superior especially when it comes to following XAML code. I love the lining up of the XAML elements when I view the page. That's not available in any older version of VS. It's a tremendous aid for me in development. Something I've not been able to convince my colleagues to do.


    Rod

    Monday, April 2, 2018 9:57 PM
  • I'm not following something you said, Karen. Are you saying that it is possible for us to use TFS 2015, to compile an application that's written for VS 2017, without having VS 2017 on the build server? (Just to make it clear, we don't, at this point, have any projects that have been started using VS 2017 that are in TFS. I'm just wondering about that possibility. I thought, given what you said, that it actually might be possible to compile a project for VS 2017 without having VS 2017 around.)

    Rod

    First off a VS2015 and VS2017 solution and projects within the solution are interchangeable in that if you start a solution in VS2015, open it in VS2017, do coding no different than in VS2015 then re-open in VS2017. 

    But let's say when opening the VS2015 solution in VS2017 and did something like the following by using a C#7 feature, local function then of course when opening the solution in VS2015 the local function is not valid. It's not Visual Studio per-say but mostly a C# 7 feature was used.

    using System;
    
    namespace BackEnd
    {
        public class Customer
        {
            public int CustomerIdentifier { get; set; }
            public string CompanyName { get; set; }
            public string ContactName { get; set; }
            public string ContactTitle { get; set; }
            public int ContactTypeIdentifier { get; set; }
            public string Address { get; set; }
            public string City { get; set; }
            public string Region { get; set; }
            public string PostalCode { get; set; }
            public string Country { get; set; }
            public string Phone { get; set; }
            public Customer() {  }
    
            public Customer(object[] pRow)
            {
                CustomerIdentifier = Convert.ToInt32(pRow[0]);
                CompanyName = Convert.ToString(pRow[1]);
                ContactName = Convert.ToString(pRow[2]);
                ContactTitle = Convert.ToString(pRow[3]);
                ContactTypeIdentifier = Convert.ToInt32(pRow[4]);
                Address = Convert.ToString(pRow[5]);
                City = Convert.ToString(pRow[6]);
    
                string RegionFixer()
                {
                    var value = Convert.ToString(pRow[7]);
                    return string.IsNullOrWhiteSpace(value) ? "(none)" : value;
    
                }
    
                Region = RegionFixer();
                PostalCode = Convert.ToString(pRow[8]);
                Country = Convert.ToString(pRow[9]);
                Phone = Convert.ToString(pRow[10]);
            }
        }
    }
    


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Monday, April 2, 2018 9:57 PM
    Moderator
  • I can see that, with the local function. I'd forgotten that was possible within C# 7. And I do try my best not to use anything C# 7 specific within the code that I work on. For example, if I remember correctly tuples in C# 7 can be returned and accessed by name, but they cannot be accessed by name in C# 6.

    But one thing. Just yesterday, on my commute home, I was watching a Pluralsight video on writing UWP apps by Andras Velvart. He was using VS 2015. I'm certain he also used Expression Bodied Members for property definitions. That makes me think it wasn't introduced with VS 2017/C# 7, but earlier. I know we started that WPF project using VS 2015, so I'm puzzled as to why it doesn't seem to like Expression Bodied Members?


    Rod

    Tuesday, April 3, 2018 2:56 PM
  • I can see that, with the local function. I'd forgotten that was possible within C# 7. And I do try my best not to use anything C# 7 specific within the code that I work on. For example, if I remember correctly tuples in C# 7 can be returned and accessed by name, but they cannot be accessed by name in C# 6.

    But one thing. Just yesterday, on my commute home, I was watching a Pluralsight video on writing UWP apps by Andras Velvart. He was using VS 2015. I'm certain he also used Expression Bodied Members for property definitions. That makes me think it wasn't introduced with VS 2017/C# 7, but earlier. I know we started that WPF project using VS 2015, so I'm puzzled as to why it doesn't seem to like Expression Bodied Members?


    Rod

    Hi Rod, Expression body members started with C# 6

    https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/expression-bodied-members


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Tuesday, April 3, 2018 4:21 PM
    Moderator