简体   繁体   中英

error CS1002: ; expected and error CS1520: Method must have a return type

I have one .cs file in my project which has below contents:

namespace Xyz.NotificationServer.Common.Helper.Configuration
{
    public static class ApplicationConfiguration
    {

        public static string Domain => "Domain".GetSettingAsString();

        public static string LdapPath => "LDAPPath".GetSettingAsString();
        public static string Referer => "Referer".GetSettingAsString();

        public static string ReportExecutionService => "ReportExecutionService".GetSettingAsString();

        public static string OAuthServer => "OAuthServer".GetSettingAsString();

        public static string DomainName => "DomainName".GetSettingAsString();

        public static string HostIpAddress => "HostIpAddress".GetSettingAsString();
        public static string Authority => "Authority".GetSettingAsString();
        public static string ClientId => "ClientId".GetSettingAsString();
        public static string ClientSecret => "ClientSecret".GetSettingAsString();
        public static string RequiredScopes => "RequiredScopes".GetSettingAsString();

        public static string To => "to".GetSettingAsString();

        /*-------------------------------Code start to read configuration string------------------------------------------*/
        public static string ConnectionString => "Default".GetConfigSettingAsString();
        /*-------------------------------Code end to read configuration string------------------------------------------*/


    }
}

The target .net framework for this project is 4.1.6. So when I'm trying to build this project using visual studio it doesn't show any error but when I'm trying to build this project from Jenkins it shows errors CS1002 and CS1520 on every line.

I have .net framework 4.1.6 installed on my machine. And in Jenkins the location of MSBUILD.EXE is pointing to below path:

C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\MSBuild.exe

So what is the issue?

This can be solved by installing the nuget package: Microsoft.Net.Compilers

Add that package to any project that uses c# 6 and then try rebuilding in Jenkins.

This might be caused by an old version of MSBuild. if you have Visual studio 2019 installed then you should have a more recent MSBuild, otherwise you should install it on your build server.

You can find MSBuild with vswhere : running vswhere -find msbuild will give you the location, and you can specify which version you are looking for.

The default location, if you have Visual Studio installed, is C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\MSBuild\\Current\\Bin\\msbuild.exe (Replacing 2019 by your visual studio version and Community with your edition as necessary)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM