Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.Net Core environment with --no-restore not working #154

Open
bcollamore opened this issue Nov 27, 2020 · 2 comments
Open

.Net Core environment with --no-restore not working #154

bcollamore opened this issue Nov 27, 2020 · 2 comments
Labels
⚠ Bug Something isn't working as expected

Comments

@bcollamore
Copy link

Per https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-build:
"Running 'dotnet build' is equivalent to running 'dotnet msbuild -restore'"

In order to not restore in a net core environment, we need to pass --no-restore.

Therefore, setting Restore = false in EnvironmentOptions does not work, as the code currently sets "/restore" when Restore == true.

Suggest using 'dotnet build' rather than 'dotnet msbuild'. In ProjectAnalyzer.GetCommand, something akin to:

        // Get the executable and the initial set of arguments
        string fileName = buildEnvironment.MsBuildExePath;
        string initialArguments = string.Empty;
        if (Path.GetExtension(buildEnvironment.MsBuildExePath).Equals(".dll", StringComparison.OrdinalIgnoreCase))
        {
            // .NET Core MSBuild .dll needs to be run with dotnet
            fileName = buildEnvironment.DotnetExePath;
            **initialArguments = "build";
            // initialArguments = $"\"{buildEnvironment.MsBuildExePath}\"";**
        }

...
// Then, at the end of the same method... something akin to

        // Get the restore argument (/restore for msbuild and --no-restore for dotnet build)
        string restoreArgument = string.Empty;
        if (initialArguments == "build" && !buildEnvironment.Restore)
        {
            restoreArgument = "--no-restore";
        }
        else if (buildEnvironment.Restore)
        {
            restoreArgument = "/restore";
        }

Context: I'm trying to use Stryker.net in a dockerized GitHub Action, and I do not want to 'restore' in the CI/CD pipeline. (1) It has already been restored, and (2) Re-restoring will not work from within a GitHub Action unless credentials of (all) the private Package Feeds are flowed into the GitHub Action, which renders it specific to the project (more specifically, to the nuget.config) being built.

@daveaglick
Copy link
Collaborator

I think I understand the problem, but not sure I'm following the suggested solution. If I recall we always call MSBuild, either directly or indirectly depending on if it's a .NET Framework or .NET Core host. I.e. we'll end up calling one of these two commands:

path/to/msbuild.exe ... or dotnet path/to/msbuild.dll ...

That help unify the command line, especially for the arguments related to injecting the MSBuild logger that Buildalyzer uses to listen for build events.

In the event Restore is true and extra /restore argument gets added:

path/to/msbuild.exe ... /restore or dotnet path/to/msbuild.dll ... /restore

If Restore is false that extra argument does not get added.

The part I'm unclear on is why calling dotnet build would help here? It sounds like from the documentation you linked that since dotnet build implies -restore that using it as the command would actually make this problem worse (since the restore argument is "baked in"). Is the problem that ``dotnet path/to/msbuild.dll ...without a/restore` argument still performs a restore?

@daveaglick daveaglick added the ⚠ Bug Something isn't working as expected label Dec 20, 2020
@bcollamore
Copy link
Author

Agreed Dave. This is incorrect. After looking more into it, my problem seems more in line with #105.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚠ Bug Something isn't working as expected
Projects
None yet
Development

No branches or pull requests

2 participants