Open augustoproiete opened 3 years ago
I think I'm running into the same issue. I'm using the dotnet-sonarscanner tool and when I try to resolve the tool it returns the netcore 2.0 version while I'm running on net5. Because we use images for our builds old versions of the sdk are not available.
To my understanding the root issue is that the tool is registered 3 times and the paths look something like this:
The ToolResolutionStrategy will return the last one registered:
private static FilePath LookInRegistrations(IToolRepository repository, string tool)
{
return repository.Resolve(tool).LastOrDefault();
}
If this method could be extended to try and match the path with the version of Dotnet that is being run the issue could be resolved.
Hey @gjhommersom, could you provide more details on how you're resolving the SonarScanner tool and some sample code?
Cake runs dotnet tool install
behind the scenes in order to install the tool, so the directive below:
#tool "dotnet:?package=dotnet-sonarscanner&version=5.2.1"
Would cause Cake to execute a command similar to the following:
dotnet tool install "dotnet-sonarscanner" --tool-path "{build.cake path}/tools" --version 5.2.1
This would install the tool in the ./tools/.store/dotnet-sonarscanner/5.2.1
folder, and create a shim to execute the tool inside ./tools
, e.g. if you're using Windows it would create a dotnet-sonarscanner.exe
which is what it the tool that would be resolved by Cake.
The same if you're installing as a global tool:
C:/Users/augustoproiete/.dotnet/tools/dotnet-sonarscanner.exe
Thus, in theory, it's .NET who's deciding which version of the SDK to use, and not Cake.
A couple of things you might want to try:
1. Force the .NET version to use when installing the tool:
#tool "dotnet:?package=dotnet-sonarscanner&version=5.2.1&framework=net5.0"
Which should execute a command similar to the following:
dotnet tool install "dotnet-sonarscanner" --tool-path "{build.cake path}/tools" --version 5.2.1 --framework net5.0
and/or
2. Add a global.json
file at the root of your repo, to force the .NET version for dotnet tool
to use:
{
"sdk": {
"allowPrerelease": false,
"version": "5.0.100",
"rollForward": "latestFeature"
}
}
I use Cake.Sonar extension. Internally it calls context.Tool.Resolve('SonarScanner.MSBuild.dll")
to get the tool. To what should that be changed because I tried using dotnet-sonarscanner.exe
. It works on my dev machine but the buildserver runs on Linux and couldn't execute the exe.
I will try the options you provided to see if I can resolve it that way.
@brianfeucht wrote:
I'm running into an issue where the Cake
DotNetCoreTool
is not able to find the tool installed with this module. It looks like the underlying issue is due to Cake and this module using different versions of the dotnet cli tool.Expected Behavior
The module and Cake use same dotnet cli version so I'm able to use the tool installed with this module.
Current Behavior
Log from my CAKE script:
Steps to Reproduce (for bugs)
Context
I'm unable to use this module to manage my global tools on our build server
Your Environment