Skip to content

Commit

Permalink
adding nuget package management inline in .csproj file
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandoescolar committed Nov 21, 2024
1 parent 75eb72b commit c966009
Show file tree
Hide file tree
Showing 22 changed files with 467 additions and 62 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All notable changes to the "vscode-solution-explorer" extension will be documented in this file.

## 0.x.x

Fixing duplicated items in the tree view: "Element with id is already registered" error

Fixing issue with terminal after executing the update all packages in project command.

Adding new nuget package management inline in a .csproj file.

## 0.8.6

Bugfix #296: Ctr+Enter hotkey should have a "when" condition to not mess with other hotkeys
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ Table of Content:
- [Create, delete, rename or move solution, solution folders and projects](#create-delete-rename-or-move-solution-solution-folders-and-projects)
- [Add or remove nuget packages](#add-or-remove-nuget-packages)
- [Update all nuget packages versions](#update-all-nuget-packages-versions)
- [Inline nuget package version management (csproj)](#inline-nuget-package-version-management-csproj)
- [Add or remove project references](#add-or-remove-project-references)
- [Create file templates](#create-file-templates)
- [Solution syntax highlighting](#solution-syntax-highlighting)
- [Extension Settings](#extension-settings)
- [Example](#example)
- [Known Issues](#known-issues)
Expand Down Expand Up @@ -204,6 +206,16 @@ Only available when the project is of kind CPS (dotnet core).

![Update all nuget packages versions](https://github.com/fernandoescolar/vscode-solution-explorer/raw/main/images/vscode-solution-explorer-update-packages-versions.gif)

### Inline nuget package version management (csproj)

Only available when the project is of kind CPS (dotnet core) c# projects.

![Inline nuget package version management (csproj)](https://github.com/fernandoescolar/vscode-solution-explorer/raw/main/images/vscode-solution-explorer-csproj-nuget-management.gif)

If you open a `.csproj` file you can see if the nuget packages versions are out-dated. You can update them by clicking on the `💡` icon and select the version you want to use. It also adds code completions for packages names and versions.

**Notes**: This feature uses caching to avoid unnecessary calls to the nuget server. If you want to force the cache update you can use the `Solution Explorer: Invalidate Nuget Cache` command.

### Add or remove project references

Only available when the project is of kind CPS (dotnet core).
Expand All @@ -222,6 +234,12 @@ We strongly recommend you to update your templates after updating this extension

![Install Or Update templates](https://github.com/fernandoescolar/vscode-solution-explorer/raw/main/images/vscode-solution-explorer-install-templates.gif)

### Solution syntax highlighting

This extension adds syntax highlighting to `.sln` files.

![Solution syntax highlighting](https://github.com/fernandoescolar/vscode-solution-explorer/raw/main/images/vscode-solution-explorer-sln-syntax.png)

## Extension Settings

You can configure the extension in the Visual Studio Code settings panel:
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/vscode-solution-explorer-sln-syntax.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"email": "[email protected]"
},
"engines": {
"vscode": "^1.70.0"
"vscode": "^1.73.0"
},
"categories": [
"Other"
Expand Down Expand Up @@ -336,6 +336,11 @@
"command": "solutionExplorer.deleteMultiple",
"title": "Delete Multiple Items",
"category": "Solution Explorer"
},
{
"command": "solutionExplorer.invalidateNugetCache",
"title": "Invalidate Nuget Cache",
"category": "Solution Explorer"
}
],
"menus": {
Expand Down
3 changes: 3 additions & 0 deletions src/SolutionExplorerCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ export class SolutionExplorerCommands {
this.commands['installTemplates'] = [new cmds.InstallWorkspaceTemplateFilesCommand(templateEngineCollection),
both(ContextValues.solution)];

this.commands['invalidateNugetCache'] = [new cmds.InvalidateNugetCacheCommand(),
undefined];

this.commands['moveFile'] = [new cmds.MoveCommand(provider),
[ContextValues.projectFile, ...fsharp(ContextValues.projectFile)]];

Expand Down
17 changes: 17 additions & 0 deletions src/actions/InvalidateNugetCache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Action, ActionContext } from "./base/Action";
import * as nuget from '@extensions/nuget';

export class InvalidateNugetCache implements Action {
constructor() {
}

public async execute(context: ActionContext): Promise<void> {
if (context.cancelled) { return; }

nuget.invalidateCache();
}

public toString(): string {
return `Invalidate Nuget cache`;
}
}
1 change: 1 addition & 0 deletions src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export * from "./DeleteSolutionFolder";
export * from "./DeleteSolutionFile";
export * from "./Focus";
export * from "./InstallWorkspaceTemplateFiles";
export * from "./InvalidateNugetCache";
export * from "./MoveProject";
export * from "./MoveProjectFile";
export * from "./MoveProjectFileUp";
Expand Down
19 changes: 19 additions & 0 deletions src/commands/InvalidateNugetCacheCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { TreeItem} from "@tree";
import { Action } from "@actions";
import { SingleItemActionsCommand } from "@commands";
import { InvalidateNugetCache } from "@actions";


export class InvalidateNugetCacheCommand extends SingleItemActionsCommand {
constructor() {
super('Invalidate Nuget Cache');
}

public shouldRun(item: TreeItem | undefined): boolean {
return true;
}

public async getActions(item: TreeItem | undefined): Promise<Action[]> {
return [new InvalidateNugetCache()];
}
}
57 changes: 3 additions & 54 deletions src/commands/UpdatePackageVersionCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { Action, AddPackageReference } from "@actions";
import { SingleItemActionsCommand } from "@commands";

export class UpdatePackageVersionCommand extends SingleItemActionsCommand {
private nugetFeeds: nuget.NugetFeed[] = [];
private lastNugetPackages: nuget.NugetPackage[] = [];
private wizard: dialogs.Wizard | undefined;
constructor() {
super('Update Package Version');
Expand All @@ -21,11 +19,11 @@ export class UpdatePackageVersionCommand extends SingleItemActionsCommand {

const projectFullPath = item.project.fullPath;
const packageId = item.path;
const version = item.description?.toString() || '';
this.wizard = new dialogs.Wizard('Update package version')
.selectOption('Select a feed', () => this.getNugetFeeds(projectFullPath) )
.selectOption('Select a version',
() => this.getCurrentPackageVersions(packageId),
() => this.getCurrentPackageDefaultVersion(packageId)
() => nuget.searchPackageVersions(projectFullPath, packageId),
version,
);

const parameters = await this.wizard.run();
Expand All @@ -35,53 +33,4 @@ export class UpdatePackageVersionCommand extends SingleItemActionsCommand {

return [ new AddPackageReference(item.project.fullPath, packageId, parameters[1]) ];
}

private async getNugetFeeds(projectFullPath: string): Promise<string[]> {
this.nugetFeeds = await nuget.getNugetFeeds(projectFullPath);
if (this.nugetFeeds.length === 0) {
const defaultNugetFeed = await nuget.getDefaultNugetFeed();
this.nugetFeeds = [ defaultNugetFeed ];
}

return this.nugetFeeds.map(f => f.name);
}

private async searchAndMapNugetPackages(packageId: string): Promise<string[]> {
if (!this.wizard || !this.wizard.context || !this.wizard.context.results) {
return [];
}

const feedName = this.wizard.context.results[0];
const feed = this.nugetFeeds.find(f => f.name === feedName);
if (!feed) { return []; }

this.lastNugetPackages = await nuget.searchNugetPackage(feed, packageId);
return this.lastNugetPackages.map(p => p.id);
}

private async getCurrentPackageVersions(packageId: string): Promise<string[]> {
if (this.lastNugetPackages.length === 0) {
await this.searchAndMapNugetPackages(packageId);
}

const nugetPackage = this.lastNugetPackages.find(p => p.id === packageId);
if (!nugetPackage) {
return Promise.resolve([]);
}

return Promise.resolve(nugetPackage.versions.map(v => v.version).reverse());
}

private async getCurrentPackageDefaultVersion(packageId: string): Promise<string> {
if (this.lastNugetPackages.length === 0) {
await this.searchAndMapNugetPackages(packageId);
}

const nugetPackage = this.lastNugetPackages.find(p => p.id === packageId);
if (!nugetPackage) {
return Promise.resolve("");
}

return Promise.resolve(nugetPackage.version);
}
}
1 change: 1 addition & 0 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export * from "./DeleteUnifiedCommand";
export * from "./DuplicateCommand";
export * from "./FocusCommand";
export * from "./InstallWorkspaceTemplateFilesCommand";
export * from "./InvalidateNugetCacheCommand";
export * from "./MoveCommand";
export * from "./MoveFileUpCommand";
export * from "./MoveFileDownCommand";
Expand Down
3 changes: 3 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { SolutionExplorerCommands } from "./SolutionExplorerCommands";
import { SolutionExplorerFileWatcher } from "./SolutionExplorerFileWatcher";
import { SolutionExplorerOutputChannel } from "./SolutionExplorerOutputChannel";
import { OmnisharpIntegrationService } from "./OmnisharpIntegrationService";
import { LanguageExtensions } from "./language";
import { TemplateEngineCollection } from "@templates";

export function activate(context: vscode.ExtensionContext) {
Expand All @@ -27,6 +28,7 @@ export function activate(context: vscode.ExtensionContext) {
const solutionExplorerFileWatcher = new SolutionExplorerFileWatcher(eventAggregator);
const solutionExplorerOutputChannel = new SolutionExplorerOutputChannel(eventAggregator);
const omnisharpIntegrationService = new OmnisharpIntegrationService(eventAggregator);
const nugetCompletionItemProvider = new LanguageExtensions(context);

register(context, config);
register(context, eventAggregator);
Expand All @@ -41,6 +43,7 @@ export function activate(context: vscode.ExtensionContext) {
register(context, solutionExplorerFileWatcher);
register(context, solutionExplorerOutputChannel);
register(context, omnisharpIntegrationService);
register(context, nugetCompletionItemProvider);
}

export function deactivate() {
Expand Down
Loading

0 comments on commit c966009

Please sign in to comment.