Skip to content

Commit

Permalink
Fixing bug for VS2022 options page not working when no solution open. (
Browse files Browse the repository at this point in the history
…#1410)

closes #1407
  • Loading branch information
belav authored Dec 20, 2024
1 parent 3c6f9ce commit 5cf6488
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 19 deletions.
8 changes: 8 additions & 0 deletions Shell/PublishVS.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ function CSH-PublishVS {
$repositoryRoot = Join-Path $PSScriptRoot ".."
$vsRoot = Join-Path $repositoryRoot "/Src/CSharpier.VisualStudio"

$msbuild = "C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\msbuild.exe"

& $msbuild $vsRoot\CSharpier.VisualStudio.sln -p:Configuration=Release

if ($LASTEXITCODE -ne 0) {
return
}

$vsixPath = "C:\Program Files\Microsoft Visual Studio\2022\Professional\VSSDK\VisualStudioIntegration\Tools\Bin\VsixPublisher.exe"

& $vsixPath publish `
Expand Down
1 change: 0 additions & 1 deletion Src/CSharpier.VisualStudio/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ Uninstalling both csharpier and csharpier 2019 from the test instance and restar
Publishing
- Update version in BOTH files at CSharpier.VisualStudio[2019]/source.extension.vsixmanifest
- Update ChangeLog.md
- build solution in release (can this happen via command line?)
- use cli
- CSH-PublishVS [AccessToken]
- old way
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="17.6.36389" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="17.6.2164">
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="17.12.40392" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="17.12.2069">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="83d6b6a0-9e25-4034-80f3-38445d8a8837" Version="1.9.0" Language="en-US" Publisher="CSharpier" />
<Identity Id="83d6b6a0-9e25-4034-80f3-38445d8a8837" Version="1.9.1" Language="en-US" Publisher="CSharpier" />
<DisplayName>CSharpier</DisplayName>
<Description xml:space="preserve">CSharpier is an opinionated code formatter for c#. It uses Roslyn to parse your code and re-prints it using its own rules.</Description>
<MoreInfo>https://github.com/belav/csharpier</MoreInfo>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<DefineConstants>TRACE;DEBUG;DEV16</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DeployExtension>False</DeployExtension>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -46,6 +47,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DeployExtension>False</DeployExtension>
</PropertyGroup>
<ItemGroup>
<None Include="source.extension.vsixmanifest">
Expand Down Expand Up @@ -76,8 +78,8 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="16.0.206" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="16.11.35" />
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="16.10.31321.278" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="16.11.69" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="edd8b38c-baa1-46c6-b82e-1da7a0ba597b" Version="1.9.0" Language="en-US" Publisher="CSharpier" />
<Identity Id="edd8b38c-baa1-46c6-b82e-1da7a0ba597b" Version="1.9.1" Language="en-US" Publisher="CSharpier" />
<DisplayName>CSharpier 2019</DisplayName>
<Description xml:space="preserve">CSharpier is an opinionated code formatter for c#. It uses Roslyn to parse your code and re-prints it using its own rules.</Description>
<MoreInfo>https://github.com/belav/csharpier</MoreInfo>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected void LoadFrom(CSharpierOptions newInstance)
ThreadHelper.JoinableTaskFactory
);

private static FileSystemWatcher _hotReloadWatcher;
private static FileSystemWatcher? hotReloadWatcher;

public static CSharpierOptions Instance
{
Expand All @@ -83,7 +83,7 @@ private static async Task<CSharpierOptions> CreateAsync()

public void Load()
{
ThreadHelper.JoinableTaskFactory.Run(LoadAsync);
ThreadHelper.JoinableTaskFactory.Run(this.LoadAsync);
}

private async Task LoadAsync()
Expand Down Expand Up @@ -140,7 +140,7 @@ await LoadOptionsFromFile(

public void Save()
{
ThreadHelper.JoinableTaskFactory.Run(SaveAsync);
ThreadHelper.JoinableTaskFactory.Run(this.SaveAsync);
}

public async Task SaveAsync()
Expand Down Expand Up @@ -204,6 +204,7 @@ await SaveOptions(

private static async Task<string?> GetSolutionOptionsFileNameAsync()
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
#pragma warning disable VSSDK006
var solution =
await AsyncServiceProvider.GlobalProvider.GetServiceAsync(typeof(SVsSolution))
Expand All @@ -212,16 +213,20 @@ await AsyncServiceProvider.GlobalProvider.GetServiceAsync(typeof(SVsSolution))
solution!.GetSolutionInfo(out _, out _, out var userOptsFile);

return userOptsFile != null
? Path.Combine(Path.GetDirectoryName(userOptsFile), "csharpier.json")
? Path.Combine(Path.GetDirectoryName(userOptsFile)!, "csharpier.json")
: null;
}

private static async Task InitializeHotReloadWatcherAsync()
{
string filePath = await GetSolutionOptionsFileNameAsync();
var filePath = await GetSolutionOptionsFileNameAsync();
if (filePath is null)
{
return;
}

_hotReloadWatcher = new FileSystemWatcher(
Path.GetDirectoryName(filePath),
hotReloadWatcher = new FileSystemWatcher(
Path.GetDirectoryName(filePath)!,
Path.GetFileName(filePath)
);

Expand All @@ -236,11 +241,11 @@ static void OnFileChanged(object sender, FileSystemEventArgs e)
#pragma warning restore
}

_hotReloadWatcher.Changed += OnFileChanged;
_hotReloadWatcher.Created += OnFileChanged;
_hotReloadWatcher.Renamed += OnFileChanged;
hotReloadWatcher.Changed += OnFileChanged;
hotReloadWatcher.Created += OnFileChanged;
hotReloadWatcher.Renamed += OnFileChanged;

_hotReloadWatcher.EnableRaisingEvents = true;
hotReloadWatcher.EnableRaisingEvents = true;
}

private class OptionsDto
Expand Down
5 changes: 4 additions & 1 deletion Src/CSharpier.VisualStudio/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## [1.9.0]
## [1.9.1]
- Fix bug if you open CSharpier options page without a solution loaded in VisualStudio

## [1.9.0]
- Configuration will hot reload: changes to `.vs/$(SolutionName)/v17/csharpier.json` will trigger a reload of the configuration in an opened Visual Studio instance.

## [1.8.0]
Expand Down

0 comments on commit 5cf6488

Please sign in to comment.