Skip to content

Commit

Permalink
Merge pull request #14 from carsten-riedel/11-add-local-packages-opti…
Browse files Browse the repository at this point in the history
…on-in-nuget-push

V0.2.47
  • Loading branch information
carsten-riedel authored Dec 2, 2023
2 parents d9e170d + 9985974 commit 704b7c2
Show file tree
Hide file tree
Showing 11 changed files with 750 additions and 21 deletions.
10 changes: 9 additions & 1 deletion src/Coree.VisualStudio.DotnetToolbar/CommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,13 @@ internal virtual async System.Threading.Tasks.Task ExecuteAsync(object sender, E
CommandSettings.Instance.MenuItem.Enabled = false;
CommandDeleteBinObj.Instance.MenuItem.Enabled = false;
CommandDotnetTest.Instance.MenuItem.Enabled = false;
CommandDotnetGlobalJson6.Instance.MenuItem.Enabled = false;
CommandDotnetGlobalJson7.Instance.MenuItem.Enabled = false;
CommandDotnetGlobalJson8.Instance.MenuItem.Enabled = false;
CommandDotnetExperimentalTest.Instance.MenuItem.Enabled = false;

await StartDotNetProcessAsync();

CommandDotnetBuild.Instance.MenuItem.Enabled = true;
CommandDotnetPack.Instance.MenuItem.Enabled = true;
CommandDotnetPublish.Instance.MenuItem.Enabled = true;
Expand All @@ -148,6 +152,10 @@ internal virtual async System.Threading.Tasks.Task ExecuteAsync(object sender, E
CommandSettings.Instance.MenuItem.Enabled = true;
CommandDeleteBinObj.Instance.MenuItem.Enabled = true;
CommandDotnetTest.Instance.MenuItem.Enabled = true;
CommandDotnetGlobalJson6.Instance.MenuItem.Enabled = true;
CommandDotnetGlobalJson7.Instance.MenuItem.Enabled = true;
CommandDotnetGlobalJson8.Instance.MenuItem.Enabled = true;
CommandDotnetExperimentalTest.Instance.MenuItem.Enabled = true;
}

internal virtual async Task StartDotNetProcessAsync()
Expand Down
155 changes: 155 additions & 0 deletions src/Coree.VisualStudio.DotnetToolbar/CommandDotnetExperimentalTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
using Coree.VisualStudio.DotnetToolbar.ExtensionMethods;
using EnvDTE;
using EnvDTE80;
using Microsoft.VisualStudio.Shell;
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Linq;
using static Microsoft.VisualStudio.Shell.ThreadedWaitDialogHelper;

namespace Coree.VisualStudio.DotnetToolbar
{
/// <summary>
/// Command handler
/// </summary>
internal sealed class CommandDotnetExperimentalTest : CommandBase
{
/// <summary>
/// Command ID.
/// </summary>
public const int CommandId = 5152;

/// <summary>
/// Command menu group (command set GUID).
/// </summary>
public static readonly Guid CommandSet = new Guid("7303216a-a2cb-4519-b645-a34ae1380a78");

internal readonly MenuCommand MenuItem;

/// <summary>
/// Initializes a new instance of the <see cref="CommandDotnetPublish"/> class.
/// Adds our command handlers for menu (commands must exist in the command table file)
/// </summary>
/// <param name="package">Owner package, not null.</param>
/// <param name="commandService">Command service to add command to, not null.</param>
private CommandDotnetExperimentalTest(AsyncPackage package, OleMenuCommandService commandService) : base(package, commandService)
{
CommandID menuCommandID = new CommandID(CommandSet, CommandId);
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
#pragma warning disable VSTHRD110 // Observe result of async calls
MenuItem = new MenuCommand((s, e) => ExecuteAsync(s, e), menuCommandID);
MenuItem.Enabled = false;
#pragma warning restore VSTHRD110 // Observe result of async calls
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed

commandService.AddCommand(MenuItem);
}

/// <summary>
/// Gets the instance of the command.
/// </summary>
public static CommandDotnetExperimentalTest Instance
{
get;
private set;
}

/// <summary>
/// Initializes the singleton instance of the command.
/// </summary>
/// <param name="package">Owner package, not null.</param>
public static async System.Threading.Tasks.Task InitializeAsync(AsyncPackage package)
{
// Switch to the main thread - the call to AddCommand in Command3's constructor requires
// the UI thread.
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);

OleMenuCommandService commandService = await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;
Instance = new CommandDotnetExperimentalTest(package, commandService);
}

/// <summary>
/// This function is the callback used to execute the command when the menu item is clicked.
/// See the constructor to see how the menu item is associated with this function using
/// OleMenuCommandService service and MenuCommand class.
/// </summary>
/// <param name="sender">Event sender.</param>
/// <param name="e">Event args.</param>
/*
internal override async System.Threading.Tasks.Task ExecuteAsync(object sender, EventArgs e)
{
CommandDotnetBuild.Instance.MenuItem.Enabled = false;
CommandDotnetPack.Instance.MenuItem.Enabled = false;
CommandDotnetPublish.Instance.MenuItem.Enabled = false;
CommandDotnetNugetPush.Instance.MenuItem.Enabled = false;
CommandDotnetClean.Instance.MenuItem.Enabled = false;
CommandSettings.Instance.MenuItem.Enabled = false;
CommandDeleteBinObj.Instance.MenuItem.Enabled = false;
await StartDotNetProcessAsync();
CommandDotnetBuild.Instance.MenuItem.Enabled = true;
CommandDotnetPack.Instance.MenuItem.Enabled = true;
CommandDotnetPublish.Instance.MenuItem.Enabled = true;
CommandDotnetNugetPush.Instance.MenuItem.Enabled = true;
CommandDotnetClean.Instance.MenuItem.Enabled = true;
CommandSettings.Instance.MenuItem.Enabled = true;
CommandDeleteBinObj.Instance.MenuItem.Enabled = true;
}
*/

internal override async System.Threading.Tasks.Task StartDotNetProcessAsync()
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(Package.DisposalToken);
DTE2 dte2 = (DTE2)await ServiceProvider.GetServiceAsync(typeof(DTE)).ConfigureAwait(false);

await WindowActivateAsync(EnvDTE.Constants.vsWindowKindOutput);

var activeConfiguration = await GetActiveSolutionConfigurationAsync();
if (activeConfiguration == null)
{
await PaneWriteLineAsync("Can't not determinate a active solution configuration.");
return;
}

string slnfile = await GetSolutionFileNameAsync();
string slndir = System.IO.Path.GetDirectoryName(slnfile);

await PaneClearAsync();

if (CoreeVisualStudioDotnetToolbarPackage.Instance.Settings.SolutionSettingsGeneral.KillAllDotnetProcessBeforeExectue)
{
(new System.Diagnostics.Process()).AllDontNetKill("dotnet");
}

List<AsyncPackageExtensions.ProjectInfo> projectInfos = new List<AsyncPackageExtensions.ProjectInfo>();

if (CoreeVisualStudioDotnetToolbarPackage.Instance.Settings.SolutionSettingsGeneral.BlockNonSdkExecute)
{
projectInfos = (await GetProjectInfosAsync()).Where(e => e.SolutionDirectoryItemNameLocationExists == true).ToList();

bool found = false;
foreach (var item in projectInfos)
{
if (item.IsSdkStyle == false)
{
await PaneWriteLineAsync("-------------------------------------------------------------------------------");
await PaneWriteLineAsync($"Non SDK style project file {item.VSProjectLocation} !");
await PaneWriteLineAsync("-------------------------------------------------------------------------------");
found = true;
}
}
if (found)
{
await PaneWriteLineAsync("Done");
return;
}
}

await ExecuteProcessAsync("dotnet.exe", $@"--version", $@"{slndir}");

await PaneWriteLineAsync("Done");
}
}
}
126 changes: 126 additions & 0 deletions src/Coree.VisualStudio.DotnetToolbar/CommandDotnetGlobalJson6.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
using Coree.VisualStudio.DotnetToolbar.ExtensionMethods;
using EnvDTE;
using EnvDTE80;
using Microsoft.VisualStudio.Shell;
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Linq;
using static Microsoft.VisualStudio.Shell.ThreadedWaitDialogHelper;

namespace Coree.VisualStudio.DotnetToolbar
{
/// <summary>
/// Command handler
/// </summary>
internal sealed class CommandDotnetGlobalJson6 : CommandBase
{
/// <summary>
/// Command ID.
/// </summary>
public const int CommandId = 5149;

/// <summary>
/// Command menu group (command set GUID).
/// </summary>
public static readonly Guid CommandSet = new Guid("7303216a-a2cb-4519-b645-a34ae1380a78");

internal readonly MenuCommand MenuItem;

/// <summary>
/// Initializes a new instance of the <see cref="CommandDotnetPublish"/> class.
/// Adds our command handlers for menu (commands must exist in the command table file)
/// </summary>
/// <param name="package">Owner package, not null.</param>
/// <param name="commandService">Command service to add command to, not null.</param>
private CommandDotnetGlobalJson6(AsyncPackage package, OleMenuCommandService commandService) : base(package, commandService)
{
CommandID menuCommandID = new CommandID(CommandSet, CommandId);
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
#pragma warning disable VSTHRD110 // Observe result of async calls
MenuItem = new MenuCommand((s, e) => ExecuteAsync(s, e), menuCommandID);
MenuItem.Enabled = false;
#pragma warning restore VSTHRD110 // Observe result of async calls
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed

commandService.AddCommand(MenuItem);
}

/// <summary>
/// Gets the instance of the command.
/// </summary>
public static CommandDotnetGlobalJson6 Instance
{
get;
private set;
}

/// <summary>
/// Initializes the singleton instance of the command.
/// </summary>
/// <param name="package">Owner package, not null.</param>
public static async System.Threading.Tasks.Task InitializeAsync(AsyncPackage package)
{
// Switch to the main thread - the call to AddCommand in Command3's constructor requires
// the UI thread.
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);

OleMenuCommandService commandService = await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;
Instance = new CommandDotnetGlobalJson6(package, commandService);
}

internal override async System.Threading.Tasks.Task StartDotNetProcessAsync()
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(Package.DisposalToken);
DTE2 dte2 = (DTE2)await ServiceProvider.GetServiceAsync(typeof(DTE)).ConfigureAwait(false);

await WindowActivateAsync(EnvDTE.Constants.vsWindowKindOutput);

var activeConfiguration = await GetActiveSolutionConfigurationAsync();
if (activeConfiguration == null)
{
await PaneWriteLineAsync("Can't not determinate a active solution configuration.");
return;
}

string slnfile = await GetSolutionFileNameAsync();
string slndir = System.IO.Path.GetDirectoryName(slnfile);

await PaneClearAsync();

if (CoreeVisualStudioDotnetToolbarPackage.Instance.Settings.SolutionSettingsGeneral.KillAllDotnetProcessBeforeExectue)
{
(new System.Diagnostics.Process()).AllDontNetKill("dotnet");
}

List<AsyncPackageExtensions.ProjectInfo> projectInfos = new List<AsyncPackageExtensions.ProjectInfo>();

if (CoreeVisualStudioDotnetToolbarPackage.Instance.Settings.SolutionSettingsGeneral.BlockNonSdkExecute)
{
projectInfos = (await GetProjectInfosAsync()).Where(e => e.SolutionDirectoryItemNameLocationExists == true).ToList();

bool found = false;
foreach (var item in projectInfos)
{
if (item.IsSdkStyle == false)
{
await PaneWriteLineAsync("-------------------------------------------------------------------------------");
await PaneWriteLineAsync($"Non SDK style project file {item.VSProjectLocation} !");
await PaneWriteLineAsync("-------------------------------------------------------------------------------");
found = true;
}
}
if (found)
{
await PaneWriteLineAsync("Done");
return;
}
}

await ExecuteProcessAsync("dotnet.exe", $@"--version", $@"{slndir}");
await ExecuteProcessAsync("dotnet.exe", $@"new globaljson --force --sdk-version 6.0.0 --roll-forward=latestFeature", $@"{slndir}");

await PaneWriteLineAsync("Done");
}
}
}
Loading

0 comments on commit 704b7c2

Please sign in to comment.