FlubuCore: Unhandled exception. FlubuCore.Scripting.ScriptLoaderExcetpion
Describe the bug
Getting error when running command flubu
on root directory with a .flubu
file
To Reproduce Steps to reproduce the behavior:
- Using this version of the library ‘Flubu v.6.1.1.0’
- Run this code
public class BuildScript : DefaultBuildScript
{
[SolutionFileName]
public string SolutionFileName { get; set; } = "ConsoleApp3.sln";
protected override void ConfigureTargets(ITaskContext context)
{
context.LogInfo("started");
var compile = context.CreateTarget("compile")
.SetDescription("Compiles the solution.")
.AddCoreTask(x => x.Build());
var clean = context.CreateTarget("Clean")
.SetDescription("Cleans the output of all projects in the solution.")
.DependsOn(compile)
.AddCoreTask(x => x.Clean());
var restore = context.CreateTarget("Restore")
.SetDescription("Restores the dependencies and tools of all projects in the solution.")
.DependsOn(clean)
.AddCoreTask(x => x.Restore());
context.CreateTarget("Default")
.SetDescription("Runs all targets.")
.SetAsDefault()
.DependsOn(restore);
}
}
.flubu file BuildScript/BuildScript.csproj
3. With these arguments compile
4. See error
Flubu v.6.1.1.0
using the build script file path from .flubu file. 'BuildScript/BuildScript.csproj'.
ScriptError:CS1525: Invalid expression term '<'
ScriptError:CS1525: Invalid expression term '<'
ScriptError:CS1525: Invalid expression term '/'
ScriptError:CS1525: Invalid expression term '<'
ScriptError:CS1525: Invalid expression term '<'
ScriptError:CS1002: ; expected
ScriptError:CS1002: ; expected
ScriptError:CS1525: Invalid expression term '>'
ScriptError:CS1525: Invalid expression term '<'
ScriptError:CS1525: Invalid expression term '/'
ScriptError:CS1525: Invalid expression term '<'
ScriptError:CS1525: Invalid expression term '<'
ScriptError:CS1002: ; expected
ScriptError:CS1002: ; expected
ScriptError:CS1525: Invalid expression term '>'
ScriptError:CS1525: Invalid expression term '<'
ScriptError:CS1525: Invalid expression term '/'
ScriptError:CS1525: Invalid expression term '<'
ScriptError:CS1525: Invalid expression term '/'
ScriptError:CS1733: Expected expression
ScriptError:CS1002: ; expected
ScriptError:CS8805: Program using top-level statements must be an executable.
ScriptError:CS0103: The name 'Project' does not exist in the current context
ScriptError:CS0103: The name 'Sdk' does not exist in the current context
ScriptError:CS0103: The name 'PropertyGroup' does not exist in the current context
ScriptError:CS0103: The name 'TargetFramework' does not exist in the current context
ScriptError:CS0103: The name 'netcoreapp3' does not exist in the current context
ScriptError:CS0103: The name 'TargetFramework' does not exist in the current context
ScriptError:CS0103: The name 'PropertyGroup' does not exist in the current context
ScriptError:CS0103: The name 'ItemGroup' does not exist in the current context
ScriptError:CS0103: The name 'PackageReference' does not exist in the current context
ScriptError:CS0103: The name 'Include' does not exist in the current context
ScriptError:CS0103: The name 'Version' does not exist in the current context
ScriptError:CS0103: The name 'ItemGroup' does not exist in the current context
ScriptError:CS0103: The name 'ItemGroup' does not exist in the current context
ScriptError:CS0103: The name 'DotNetCliToolReference' does not exist in the current context
ScriptError:CS0103: The name 'Include' does not exist in the current context
ScriptError:CS0103: The name 'Version' does not exist in the current context
ScriptError:CS0103: The name 'ItemGroup' does not exist in the current context
ScriptError:CS0103: The name 'Project' does not exist in the current context
Unhandled exception. FlubuCore.Scripting.ScriptLoaderExcetpion: Csharp source code file: BuildScript/BuildScript.csproj has some compilation errors! If your script doesn't have compilation errors in VS or VSCode script probably doesn't include .cs file. To resolve this issue you should see build script fundamentals section 'Adding other .cs files to script' for more details: https://flubucore.dotnetcore.xyz/referencing-external-assemblies/#adding-other-cs-files-to-script
at FlubuCore.Scripting.ScriptLoader.CompileBuildScript(String buildScriptAssemblyPath, String buildScriptFilePath, IEnumerable`1 references, String code) in c:\jenkins\workspace\FlubuCore\src\FlubuCore\Scripting\ScriptLoader.cs:line 250
at FlubuCore.Scripting.ScriptLoader.FindAndCreateBuildScriptInstanceAsync(CommandArguments args) in c:\jenkins\workspace\FlubuCore\src\FlubuCore\Scripting\ScriptLoader.cs:line 124
at FlubuCore.Scripting.ScriptProvider.GetBuildScriptAsync(CommandArguments commandArguments, Boolean forceReload) in c:\jenkins\workspace\FlubuCore\src\FlubuCore\Scripting\ScriptProvider.cs:line 26
at DotNet.Cli.Flubu.Program.FlubuStartup(String[] args) in c:\jenkins\workspace\FlubuCore\src\dotnet-flubu\Program.cs:line 84
at DotNet.Cli.Flubu.Program.Main(String[] args) in c:\jenkins\workspace\FlubuCore\src\dotnet-flubu\Program.cs:line 36
at FlubuCore.Tool.Program.Main(String[] args) in c:\jenkins\workspace\FlubuCore\src\FlubuCore.Tool\Program.cs:line 9
at FlubuCore.Tool.Program.<Main>(String[] args)
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 18
@sreejith-ms Issue with interfaces is fixed in 6.1.3-preview1. Usage statements inside namespace should work to. It looks like this issue was related with interface issue. I have tested few scenarios and it worked fine.
Btw: If you are using flubu global tool don’t forget to update the tool also to 6.1.3-preview1 version .
Didn’t notice your question before.
I’ve noticed .flubu file is not documented good enough. I will add documentation for it to getting started guide
.flubu file can contain path to buildscript and csproj file as mentioned in one of my comments above. this is usefull when you don’t want those 2 files at default locations where flubu searches for those files. It is also used to determinate the root directory / working folder as described here:
https://flubucore.dotnetcore.xyz/execute-script-in-console-app-or-pack-as-global-tool/
FlubuCore command line tool has an option to help you create .flubu file, simply type flubu setup and interactive mode will guide you through.
Yes that will work. I have tested it in my test console app and it worked. Problem with this solution might be that if you will run your build on build server you will have to compile console app locally and commit it. or first run dotnet build to compile the console app and then run the build with console app.
https://github.com/dotnetcore/FlubuCore/blob/develop/src/FlubuCore/Scripting/Analysis/ProjectFileAnalyzer.cs Correct file location is here. I will fix the documentation.
But if you have location of csproj file defined in .flubu file it doesn’t need to be at the default locations defined in ProjectFileAnalyzer.cs
I think that the root of the problem might be this error
ScriptError:CS1529: A using clause must precede all other elements defined in the namespace except extern alias declarations
That’s why I would like to see your buildscript.
I think that the .flubu file in your scenario has wrong data. How did you create .flubu file?
.flubu file should contain at line 1 path to build script. For example: BuildScript/BuildScript.cs .flubu file should contain at line 2 path to project file. For example BuildScript/BuildScript.csproj
From your log it looks like that ‘BuildScript/BuildScript.csproj’ is at line 1 in .flubu file and because of that it tries to compile csproj file instead of .cs file.
.flubu file can contain only path to build script file or path to project file but both paths must be at correct lines in .flubu file.
.flubu file can also be empty. Then it will look for both files at default locations. Actually it doesn’t need to exist at all but it has some benefits if .flubu file is created. I would not go into details at the moment.