简体   繁体   English

错误 CS1002: ; 预期和错误 CS1520:方法必须具有返回类型

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

I have one .cs file in my project which has below contents:我的项目中有一个 .cs 文件,其中包含以下内容:

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.该项目的目标 .net 框架是 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.因此,当我尝试使用 Visual Studio 构建此项目时,它不会显示任何错误,但是当我尝试从 Jenkins 构建此项目时,它会在每一行上显示错误 CS1002 和 CS1520。

I have .net framework 4.1.6 installed on my machine.我的机器上安装了 .net framework 4.1.6。 And in Jenkins the location of MSBUILD.EXE is pointing to below path:在 Jenkins 中,MSBUILD.EXE 的位置指向以下路径:

C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\MSBuild.exe 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这可以通过安装 nuget 包来解决:Microsoft.Net.Compilers

Add that package to any project that uses c# 6 and then try rebuilding in Jenkins.将该包添加到任何使用 c# 6 的项目,然后尝试在 Jenkins 中重建。

This might be caused by an old version of MSBuild.这可能是由旧版本的 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.如果你安装了 Visual Studio 2019,那么你应该有一个更新的 MSBuild,否则你应该将它安装在你的构建服务器上。

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.您可以使用vswhere找到 MSBuild:运行vswhere -find msbuild将为您提供位置,您可以指定要查找的版本。

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)如果安装了 Visual Studio,默认位置是C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\MSBuild\\Current\\Bin\\msbuild.exe (用你的 Visual Studio 版本和社区替换2019根据需要编辑)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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