Skip to content

Commit 5cf6488

Browse files
authored
Fixing bug for VS2022 options page not working when no solution open. (#1410)
closes #1407
1 parent 3c6f9ce commit 5cf6488

8 files changed

Lines changed: 36 additions & 19 deletions

File tree

Shell/PublishVS.psm1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ function CSH-PublishVS {
77
$repositoryRoot = Join-Path $PSScriptRoot ".."
88
$vsRoot = Join-Path $repositoryRoot "/Src/CSharpier.VisualStudio"
99

10+
$msbuild = "C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\msbuild.exe"
11+
12+
& $msbuild $vsRoot\CSharpier.VisualStudio.sln -p:Configuration=Release
13+
14+
if ($LASTEXITCODE -ne 0) {
15+
return
16+
}
17+
1018
$vsixPath = "C:\Program Files\Microsoft Visual Studio\2022\Professional\VSSDK\VisualStudioIntegration\Tools\Bin\VsixPublisher.exe"
1119

1220
& $vsixPath publish `

Src/CSharpier.VisualStudio/CONTRIBUTING.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ Uninstalling both csharpier and csharpier 2019 from the test instance and restar
77
Publishing
88
- Update version in BOTH files at CSharpier.VisualStudio[2019]/source.extension.vsixmanifest
99
- Update ChangeLog.md
10-
- build solution in release (can this happen via command line?)
1110
- use cli
1211
- CSH-PublishVS [AccessToken]
1312
- old way

Src/CSharpier.VisualStudio/CSharpier.VisualStudio/CSharpier.VisualStudio.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@
7676
<Reference Include="System.Xml" />
7777
</ItemGroup>
7878
<ItemGroup>
79-
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="17.6.36389" ExcludeAssets="runtime" />
80-
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="17.6.2164">
79+
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="17.12.40392" ExcludeAssets="runtime" />
80+
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="17.12.2069">
8181
<PrivateAssets>all</PrivateAssets>
8282
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
8383
</PackageReference>

Src/CSharpier.VisualStudio/CSharpier.VisualStudio/source.extension.vsixmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<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">
33
<Metadata>
4-
<Identity Id="83d6b6a0-9e25-4034-80f3-38445d8a8837" Version="1.9.0" Language="en-US" Publisher="CSharpier" />
4+
<Identity Id="83d6b6a0-9e25-4034-80f3-38445d8a8837" Version="1.9.1" Language="en-US" Publisher="CSharpier" />
55
<DisplayName>CSharpier</DisplayName>
66
<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>
77
<MoreInfo>https://github.com/belav/csharpier</MoreInfo>

Src/CSharpier.VisualStudio/CSharpier.VisualStudio2019/CSharpier.VisualStudio2019.csproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<DefineConstants>TRACE;DEBUG;DEV16</DefineConstants>
3939
<ErrorReport>prompt</ErrorReport>
4040
<WarningLevel>4</WarningLevel>
41+
<DeployExtension>False</DeployExtension>
4142
</PropertyGroup>
4243
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
4344
<DebugType>pdbonly</DebugType>
@@ -46,6 +47,7 @@
4647
<DefineConstants>TRACE</DefineConstants>
4748
<ErrorReport>prompt</ErrorReport>
4849
<WarningLevel>4</WarningLevel>
50+
<DeployExtension>False</DeployExtension>
4951
</PropertyGroup>
5052
<ItemGroup>
5153
<None Include="source.extension.vsixmanifest">
@@ -76,8 +78,8 @@
7678
<Reference Include="System.Xml" />
7779
</ItemGroup>
7880
<ItemGroup>
79-
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="16.0.206" ExcludeAssets="runtime" />
80-
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="16.11.35" />
81+
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="16.10.31321.278" ExcludeAssets="runtime" />
82+
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="16.11.69" />
8183
</ItemGroup>
8284
<ItemGroup>
8385
<Folder Include="Properties\" />

Src/CSharpier.VisualStudio/CSharpier.VisualStudio2019/source.extension.vsixmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<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">
33
<Metadata>
4-
<Identity Id="edd8b38c-baa1-46c6-b82e-1da7a0ba597b" Version="1.9.0" Language="en-US" Publisher="CSharpier" />
4+
<Identity Id="edd8b38c-baa1-46c6-b82e-1da7a0ba597b" Version="1.9.1" Language="en-US" Publisher="CSharpier" />
55
<DisplayName>CSharpier 2019</DisplayName>
66
<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>
77
<MoreInfo>https://github.com/belav/csharpier</MoreInfo>

Src/CSharpier.VisualStudio/CSharpier.VisualStudioShared/CSharpierOptions.cs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ protected void LoadFrom(CSharpierOptions newInstance)
6060
ThreadHelper.JoinableTaskFactory
6161
);
6262

63-
private static FileSystemWatcher _hotReloadWatcher;
63+
private static FileSystemWatcher? hotReloadWatcher;
6464

6565
public static CSharpierOptions Instance
6666
{
@@ -83,7 +83,7 @@ private static async Task<CSharpierOptions> CreateAsync()
8383

8484
public void Load()
8585
{
86-
ThreadHelper.JoinableTaskFactory.Run(LoadAsync);
86+
ThreadHelper.JoinableTaskFactory.Run(this.LoadAsync);
8787
}
8888

8989
private async Task LoadAsync()
@@ -140,7 +140,7 @@ await LoadOptionsFromFile(
140140

141141
public void Save()
142142
{
143-
ThreadHelper.JoinableTaskFactory.Run(SaveAsync);
143+
ThreadHelper.JoinableTaskFactory.Run(this.SaveAsync);
144144
}
145145

146146
public async Task SaveAsync()
@@ -204,6 +204,7 @@ await SaveOptions(
204204

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

214215
return userOptsFile != null
215-
? Path.Combine(Path.GetDirectoryName(userOptsFile), "csharpier.json")
216+
? Path.Combine(Path.GetDirectoryName(userOptsFile)!, "csharpier.json")
216217
: null;
217218
}
218219

219220
private static async Task InitializeHotReloadWatcherAsync()
220221
{
221-
string filePath = await GetSolutionOptionsFileNameAsync();
222+
var filePath = await GetSolutionOptionsFileNameAsync();
223+
if (filePath is null)
224+
{
225+
return;
226+
}
222227

223-
_hotReloadWatcher = new FileSystemWatcher(
224-
Path.GetDirectoryName(filePath),
228+
hotReloadWatcher = new FileSystemWatcher(
229+
Path.GetDirectoryName(filePath)!,
225230
Path.GetFileName(filePath)
226231
);
227232

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

239-
_hotReloadWatcher.Changed += OnFileChanged;
240-
_hotReloadWatcher.Created += OnFileChanged;
241-
_hotReloadWatcher.Renamed += OnFileChanged;
244+
hotReloadWatcher.Changed += OnFileChanged;
245+
hotReloadWatcher.Created += OnFileChanged;
246+
hotReloadWatcher.Renamed += OnFileChanged;
242247

243-
_hotReloadWatcher.EnableRaisingEvents = true;
248+
hotReloadWatcher.EnableRaisingEvents = true;
244249
}
245250

246251
private class OptionsDto

Src/CSharpier.VisualStudio/ChangeLog.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
## [1.9.0]
1+
## [1.9.1]
2+
- Fix bug if you open CSharpier options page without a solution loaded in VisualStudio
3+
4+
## [1.9.0]
25
- Configuration will hot reload: changes to `.vs/$(SolutionName)/v17/csharpier.json` will trigger a reload of the configuration in an opened Visual Studio instance.
36

47
## [1.8.0]

0 commit comments

Comments
 (0)