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

C# scripts with NuGet package references fail to execute correctly via Husky.NET #133

Open
kechf opened this issue Apr 2, 2025 · 1 comment
Labels
bug Something isn't working need more information Need more information

Comments

@kechf
Copy link

kechf commented Apr 2, 2025

Version

0.7.2

Details

When running C# scripts that include NuGet package references (using the #r "nuget: ..." directive) via Husky.NET hooks, the script fails to execute properly. However, when the same script is executed directly using dotnet script, it works as expected.

Actual Behavior:
The script fails with an error indicating that the metadata file for the NuGet package (e.g., "nuget: Framework.Common.GitHook, 1.0.0") was not found, causing script compilation to fail.

Additional Information:

  • Running the script directly with dotnet script works without issues.
  • It appears that Husky.NET’s execution environment might not be resolving NuGet package references correctly.
  • Please let me know if additional information (e.g., Husky.NET version, .NET SDK version, OS details) would be helpful.

Steps to reproduce

  1. Create a C# script (e.g., commit-lint.csx) with a NuGet package reference, for example:
    #!/usr/bin/env dotnet-script
    #r "nuget: Framework.Common.GitHook, 1.0.0"
    
    using System;
    using System.IO;
    using Framework.Common.GitHook;
    
    var msg = File.ReadAllLines(Args[0])[0];
    var result = ConventionalCommitValidator.Validate(msg);
    Console.WriteLine(result);
    if (result)
    {
        return 0;
    }
    
    Console.ForegroundColor = ConsoleColor.Red;
    Console.WriteLine("Invalid commit message");
    Console.ResetColor();
    Console.WriteLine("e.g.: 'feat(scope): subject' or 'fix: subject'");
    Console.WriteLine("or a valid merge commit message, e.g.: \"Merge branch 'master' into 'develop'\"");
    Console.ForegroundColor = ConsoleColor.Gray;
    Console.WriteLine("more info: https://www.conventionalcommits.org/en/v1.0.0/");
    return 1;
  2. Configure Husky.NET to run this script as a commit hook, for example:
    dotnet script --no-cache .husky/csx/commit-lint.csx -- commit-message.txt
  3. Commit changes so that the Husky hook is triggered.

Expected Behavior:
The script should execute the NuGet package reference successfully (as it does when using dotnet script directly) and perform its validation without error.

@kechf kechf added the bug Something isn't working label Apr 2, 2025
@alirezanet
Copy link
Owner

Hi @kechf,
This package (Framework.Common.GitHook) doesn't exist in nuget

Are you sure it works with dotnet script!?

dotnet script .husky\csx\commit-lint.csx
Unable to restore packages from 'C:\Users\AliReza\AppData\Local\Temp\dotnet-script\C\Users\AliReza\source\Husky.Net\.husky\csx\net9.0\script.csproj'
Make sure that all script files contains valid NuGet references

@alirezanet alirezanet added the need more information Need more information label Apr 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working need more information Need more information
Projects
None yet
Development

No branches or pull requests

2 participants