简体   繁体   中英

How to compile .netcore 2.2 project in cake

We are developing Asp.Net core v2.2 .netcore Web API Application and following CI in our company.

We have tried below code in Cake Script but facing below error while compilation.

Error:

error NETSDK1045: The current .NET SDK does not support targeting .NET Core 2.2. Either target .NET Core 2.1 or lower, or use a version of the .NET SDK that supports .NET Core 2.2

Cake Script:

Task("Build")   
    .IsDependentOn("Clean")
    .IsDependentOn("Restore")
    .Does(() => {   
    try {
       MSBuild(solutionFile , settings => settings.SetConfiguration(configuration));
       }    
    catch(Exception ex) {        
        throw new Exception(String.Format("Please fix the project compilation failures"));  
    }
    });

Cake Version : 0.23.0

How to set the -framework property value .netcoreapp2.2 in Msbuild Action or anyother method to compile this ?

In order to take Cake out of the question, can I suggest that you run the above Cake Script with Diagnostic verbosity enabled. See here for information on how to do this:

How to enable diagnostic verbosity for Cake

This will then show you the command that Cake is executing which is resulting in this error. Take this command and run it directly from the command line, and you should get the same result.

Now that we have ruled Cake out as causing the problem, we need to fix the underlying issue, and in this case, I think the error message is telling you exactly what the problem is, ie you don't have the correct .Net SDK installed on your machine. I suspect you are going to need to install a newer version.

Upgraded Cake to 0.32.0 and run the below code.

MSBuild(solutionFile , new MSBuildSettings {
    Verbosity = Verbosity.Minimal,
    ToolVersion = MSBuildToolVersion.VS2019,
    Configuration = "Release",
    PlatformTarget = PlatformTarget.MSIL
    });

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