Invalid Expression Term '.' Running Visual Studio 2017 and TFS Build 2015 - msbuild

I'm setting up a new CI build server using TFS Build 2015 (XAML - I know I have to move to vNEXT.) and Visual Studio 2017.
My build is breaking with Invalid expression term '.'. The code that is problematic syntax is...
addVaultAction?.Invoke(this, vault)
If replaced with...
if (addVaultAction != null)
addVaultAction.Invoke(this, valut)
... the CI build doesn't trip up.
The problematic code also compiles fine within Visual Studio 2017, but during the CI build (MSBuild) it fails.
Also, this code did exist on our previous build server which ran TFS Build 2015 and Visual Studio 2015 and the CI/MSBuild compiles completed successfully.
It would appear something is missing on my new build server. Does anyone know what that might be? Or is it that TFS 2015 and VS 2017 do not play nice together.
I've seen reference to making sure Microsoft.Net.Compilers is up to date but, if related to this problem at all, I don't know how or where to check on that.
Any help GREATLY appreciated!
Thanks!

Invalid Expression Term '.' Running Visual Studio 2017 and TFS Build 2015
You can try to use MSBuild task to build your project and specify the MSBuild version to 15.0 or the latest, or specify the MSBuild 15.0 location with radio button Specify Location, like:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\MSBuild.exe

Related

Visual Studio 2022 not showing up in the dropdown

We have on-prem Azure DevOps 2020 installed. We built a .net core 6 app in Visual Studio 2022.
However, when creating the build pipeline, VS 2022 is not showing up in the dropdown.
Has anyone faced this problem? Is MSFT supposed to release a patch that will start displaying VS 2022 in the dropdown?
Many people are running into this. No word from MS yet on when or if an update will be available. But these articles may help you find a workaround:
How do I update my Azure DevOps on-premise Pipeline tasks to include MSBuild v17 and Visual Studio 2022?
https://jessehouwing.net/adding-visual-studio-2022-to-azure-devops-server-2020/
https://github.com/microsoft/azure-pipelines-agent/issues/3662
FWIW, I'm working around it by using an explicit MSBuild path as mentioned in this answer. I added a PreferredMSBuildExePath variable to my pipeline and set it equal to %ProgramFiles%\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\amd64\MSBuild.exe. Then I made all my MSBuild steps use $(PreferredMSBuildExePath) as their MSBuild path under Specify Location. I also converted all my Visual Studio steps to MSBuild steps so I could use this explicit path variable.

Not able to restore nuget packages/Manage nuget packages not working in visual studio 2017

I tried to open a .Net Core solution which was working fine in 2015. Recently they added some .Net Core projects to the solution and asked us to upgrade to Visual Studio 2017 to be able to run them. We installed Visual Studio 2017 and tried to open the solution, but I am not able to build it. I get the following errors when I right-click and try to select "Manage Nuget packages".
I tried to open the PackageManager console from Tools: even this is not working
I also performed the "repair Visual Studio" process too.
Finally i resolved it by deleting my nuget.config both at project level and also in %appdata%/roaming/nuget .I think the issue is because of broken config file due to change from visual 2015 to visual studio 2017 .Not sure about the exact issue though

How to use Visual Studio 2017 with TFS Visual Studio Build Step

I am running TFS 2015 and are using the Visual Studio Build Step. On the developemnt machines I moved to use Visual Studio 2017 so I also want to use Visual Studio 2017 for the TFS builds.
I installed Visual Studio 2017 on the build server and restarted the build agent. However Visual Studio 2017 does not show up in the capabilities of the agent and it also does not show in the list of Visual Studio versions in the build step.
I know I can choose "latest" from the list of Visual Studio version in the build step, but this will still use VS 2015 as the agent does not know that it has VS 2017.
How can I make sure that the Visual Studio Build Step in TFS2015 uses Visual Studio 2017?
You can use MSBuild task instead of Visual Studio Build Step, then specify the location of MSBuild 15.0:
In TFS 2015 the build steps and forward compatibility is only updated when TFS is updated. If you are using TFS 2015.3 already then you will need to move to TFS 2017 to use this out of the box.
The build step ultimately calls out to devenv.exe and the drop down changes the path. You can call out manually to VS 2017...

TFS 2015 visual studio build task does not support VS 2017

We have a build definition in TFS 2015 that have worked fine with Visual Studio 2015 projects and solutions. We have now decided to upgrade to Visual Studio 2017 and thus we would like to target Visual Studio 2017 in the Visual Studio build task. We have installed Visual Studio 2017 on the build agent. Unfortunately the only options available int the Visual Studio build task are 2012, 2013, 2015 and Latest. We have tried latest but it does not find Visual Studio 2017 on the build agent. It won't work with the msbuild task either.
I have a similiar issue and resolved by installing VS2017 in my build agent server and configuring MSBuild to point to my MSBuild 15.0 folder:
Add MSBuild to your build steps
On the Advanced options, expand and fill the 'Path to MSBuild' like the image below:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin
VS2017 RTM is released recently while TFS2015 was released before. That's why there is no VS2017 option in VS Build Task in TFS2015 Server. If you upgrade your server to the latest TFS2017, you would see "Visual Studio "15" (preview)" option listed in VS Build Task which is the version for VS2017 preview. And in the feature, the option will be updated to VS2017 which is the same as VSTS.
we are facing a similar issue and it is not possible for us to update ourselves as it is maintained on a company level where we cannot take that much influence.
However our team wanted to switch to VS2017 and make use of the C# 7 features. That's why we tried it as well with replacing the build steps from Visual Studio Build to MSBuild. Sadly this did not work as expected (we got some errors during the build).
As our main objective is to use the C# 7 features we looked for a way how to still achieve that at the time with Visual Studio 2015 remaining on the Build Server. We ended up using the nuget package Microsoft.Net.Compilers that, when used in a project, will use that compiler instead of the installed one.
More on this can be found in this Thread.
It seems the updates to the build tools are installed via the command line of the VS2017 installer.
See the docs for details.
Just adding another thing: if you're using custom build template make sure to edit it and modify the ToolPath attribute value to:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin

Why does my build app fail when run outside of VS12 (i.e. when deployed)?

I've written a c# program that builds *.csproj and *.vcxproj using Microsoft.Build.Evaluation. It works great on both project types if I compile and run it from inside Visual Studio 12. But if I run the exe directly (outside of Visual Studio) I get the example error message below. The error occurs only for vcx projects; c# projects continue to build just fine
Question: Why am I getting this error? Why does my program work fine for both C# and vcx projects when run from within VS12, but fails, but only for vcx projects, when run outside of VS12?
Please don't chastise me for not using MSBuild.exe. My orders were to programmatically build C# and vcx projects using Microsoft.Build.Evaluation.
Code:
using Microsoft.Build.Evaluation;
...
Project proj = new Project("MyCppProject.vcxproj");
proj.Build(logger);
Runtime Error:
Building MyCppProject
Project "MyCppProject.vcxproj" (default targets):
VCMessage:
ERROR C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Platforms\Win32\Microsoft.Cpp.Win32.Targets(518,5): Specified platform toolset (v110) is not installed or invalid. Please make sure that a supported PlatformToolset value is selected.
Done building project "MyCppProject" -- FAILED.
One solution is to force the Visual Studio version as an environment variable prior to loading and building the project:
using Microsoft.Build.Evaluation;
...
Environment.SetEnvironmentVariable("VisualStudioVersion", "11.0")
Project proj = new Project("MyCppProject.vcxproj");
proj.Build(logger);
Visual studio maintains platform tool sets list supported for the version of Visual studio you are currently running for example on my machine I have VS 2008, 2010 and 2012
Now suppose when I install Visual Studio 2013 which has a Platform Toolset version of V120. What happens, is that the project saves this in its corresponding XML files in the format (vcproj, vcxproj, vcxproj.filter.user files).
now this valus is not known to VS 2012 so it complains when opened in VS 2012.
Similarly for opening VS 2012 project in VS 2010, as in your case and so on.
Solution:
To fix this issue, Open you solution file in notepad++.
Make these 2 changes
1) Replace
Format Version 12.00
with
Format Version 11.00
2) Replace
Visual Studio 2012
with
Visual Studio 2010
Then open the file again in visual studio and rebuild solution.