2
votes

My project builds successfully in VS2017 but fails on Jenkins using an old MSBuild (v14.0 C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe). The error log shows that there were missing characters like semi colons and curly brackets. I looked into the files where they were failing and most of the "errors" were referring to this method call below.

if (cache.TryGetProxyById<ResultTagTypeProxy, ResultTagType>(this.ResultTagTypeId, out var existingTagType))
                this.ResultTagType = existingTagType;
public TProxy GetOrCreateProxy<TProxy, TModel>(TModel navModel, Func<TModel, ProxyCache, TProxy> proxyConstructor)
            where TProxy : ModelProxyBase<TModel>
            where TModel : IDatabaseEntity
        {
            TProxy navProxy = null;

            // Set the navigation property if it already exists in the cache by model
            if (this.TryGetProxyByModel<TProxy, TModel>(navModel, out var existingProxy))
                navProxy = existingProxy;
            else if (navModel != null)
            {
                // Else try loading by id
                if (this.TryGetProxyById<TProxy, TModel>(navModel.Id, out existingProxy))
                    navProxy = existingProxy;
                // Else create a
                else
                    navProxy = proxyConstructor(navModel, this);
            }

            return navProxy;
        }

I believe the problem is because this MSBuild does not support C# 7 new features and I would need to download a new MSBuild. I've been using chocolatey to install my packages and I installed 'microsoft-build-tools'.

Using the new MSBuild in the build tools path (C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSbuild.exe), I found out that there were different compilation errors. The first error was one of my projects needed a referenced to netstandard 2.0. After fixing that reference, more references could not be found in my Functional Tests project.

I was wondering if this change (moving from MSBuild 14.0 to MSBuild 15.0) is expected. Everything up to the functional test project compiles successfully...

3
Looks like you're using C# 7 features with out var existingTagType. As far as I know, you'll need to move to MSBuild 15.0 to support this.Jonathon Chase
Hi friend, any update for this issue?Just checking in to see if the answers provided were helpful. Please let us know if you would like further assistance.LoLance

3 Answers

1
votes

I was wondering if this change (moving from MSBuild 14.0 to MSBuild 15.0) is expected. Everything up to the functional test project compiles successfully...

1.We always recommend using msbuild tools whose version correspond to vs version.

Since your project comes from VS2017 and builds well in it. When you need to build it outside VS IDE, Build tools for VS2017(Msbuild 15.0) package should be the good choice.

ps: VS2015 <=> MSBuild14.0, VS2017 <=> MSBuild15.0

Default path for msbuild.exe in build tools for vs2017 package: C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin

2.Also, as what described in Jonathon's comment, to support C# 7 features we need to use Msbuild15.0 version.

Assuming you have two projects(A and B, A uses C#7 and B not).In your CI server you can use msbuild14.0 to build B but not A, if you have msbuild15.0, you can use it to build A and B and etc.

So moving from 14.0 to 15.0 is an expected choice I think.

In addition:

Create a new C# project in vs, and Right-click Project=>Properties=>Build=>Advanced you can find the language version list.

First pic for vs2015 and msbuild14.0 and second one for vs2017 and msbuild15.0:

enter image description here enter image description here

1
votes

You should use the VS 2017 (build tools) version of msbuild.exe which is located in the VS 2017 installation folder and not in C:\Program Files (x86)\MSBuild. I suggest using vswhere to locate the path to msbuild.exe.

Alternatively, you can use the Microsoft.Net.Compilers NuGet package in your project to get the latest C# compiler to replace the default ones used by MSBuild/Visual Studio, but it will also override the toolset while developing, slowing compilation down a bit and causing different diagnostics and build behaviour.

1
votes

You msbuild14 is visual studio 2015 You must use msbuild15.