Skip to content

Initial ecosystem implementation for .NET/C#. #3698

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

Merged
merged 1 commit into from
Aug 7, 2025
Merged

Conversation

mitchell-as
Copy link
Contributor

@mitchell-as mitchell-as commented Aug 6, 2025

StoryCP-980 Implement C# ecosystem installer in State Tool

The dotnet command, provided by the .NET runtime/SDK, functions like npm for JavaScript. It replaces nuget's functionality. (This means it is possible to use dotnet to pull down packages from the nuget online package registry.) We cannot use nuget in Linux because of it's dependency on Mono, which is a large framework we should absolutely not depend on.

However, dotnet requires a project to operate in, so we cannot install *.nupkg artifacts directly like we can with npm. Instead, we unpack *.nupkg artifacts into a directory structure dotnet recognizes. Then users can build their own projects using our packages.

image

The order of operations is:

  • Checkout a .NET Platform project.
  • Install a .NET package.
  • Start a shell for the project, which sets the $NUGET_PACKAGES environment variable that points to our virtual environment's package listing.
  • Go to your .NET project and run dotnet restore, which will read your .NET project's project file and verify you have all the required dependencies (which should be in our virtual environment).
  • Build and run the .NET project.

After the state install command, I turned off my network to confirm that dotnet can detect and use packages in our virtual environment.

It's a bit unfortunate that dotnet restore needs the --source $NUGET_PACKAGES argument, but oh well. It's certainly possible that people building against a local package listing have to do something similar to prevent a reachout to the nuget registry, so it may not be so bad.


func (e *DotNet) Init(runtimePath string, buildplan *buildplan.BuildPlan) error {
e.runtimePath = runtimePath
e.nupkgDir = filepath.Join("usr", "nupkg")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default .NET package registry lives in the user's ~/.nuget/packages/ directory. We can override this with the $NUGET_PACKAGES environment variable, and we'll point it to this directory: /usr/nupkg/.

@mitchell-as mitchell-as marked this pull request as ready for review August 7, 2025 18:54
@mitchell-as mitchell-as requested a review from Naatan August 7, 2025 18:55
Copy link
Member

@Naatan Naatan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ok to me, one minor nit.

Comment on lines +49 to +58
if file.Name() == "runtime.json" {
err = injectEnvVar(file.AbsolutePath(), "NUGET_PACKAGES", "${INSTALLDIR}/"+e.nupkgDir)
if err != nil {
return nil, errs.Wrap(err, "Unable to add NUGET_PACKAGES to runtime.json")
}
continue
}
if !strings.HasSuffix(file.Name(), ".nupkg") {
continue
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if file.Name() == "runtime.json" {
err = injectEnvVar(file.AbsolutePath(), "NUGET_PACKAGES", "${INSTALLDIR}/"+e.nupkgDir)
if err != nil {
return nil, errs.Wrap(err, "Unable to add NUGET_PACKAGES to runtime.json")
}
continue
}
if !strings.HasSuffix(file.Name(), ".nupkg") {
continue
}
if !strings.HasSuffix(file.Name(), ".nupkg") {
continue
}
if file.Name() == "runtime.json" {
err = injectEnvVar(file.AbsolutePath(), "NUGET_PACKAGES", "${INSTALLDIR}/"+e.nupkgDir)
if err != nil {
return nil, errs.Wrap(err, "Unable to add NUGET_PACKAGES to runtime.json")
}
continue
}

Reduce chance for failures.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, that will prevent a runtime.json file from ever being processed. If there wasn't a !, then I'd agree with your proposed changes.

@mitchell-as mitchell-as requested a review from Naatan August 7, 2025 20:51
@mitchell-as mitchell-as merged commit bd0b267 into master Aug 7, 2025
7 of 8 checks passed
@mitchell-as mitchell-as deleted the mitchell/cp-980 branch August 7, 2025 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants