Skip to content

Commit 2894c0c

Browse files
committed
Remove brittle active document tracking
The workarounds to access the running document table was brittle, caused VS to fail to exit sometimes (hanging on the MSBuild process), etc. So we'll just keep the MSBuild-only part of generating the launch profiles for each top-level file and honoring the user's selection for Run.
1 parent 8d24e50 commit 2894c0c

9 files changed

Lines changed: 9 additions & 662 deletions

SmallSharp.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
1717
.github\workflows\publish.yml = .github\workflows\publish.yml
1818
EndProjectSection
1919
EndProject
20-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SmallSharp", "src\SmallSharp\SmallSharp.csproj", "{97648980-AA30-4AC0-B8E9-FCF6359F56A0}"
20+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SmallSharp", "src\SmallSharp\SmallSharp.msbuildproj", "{97648980-AA30-4AC0-B8E9-FCF6359F56A0}"
2121
EndProject
2222
Global
2323
GlobalSection(SolutionConfigurationPlatforms) = preSolution

readme.md

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33

44
[![Version](https://img.shields.io/nuget/v/SmallSharp.svg?color=royalblue)](https://www.nuget.org/packages/SmallSharp) [![Downloads](https://img.shields.io/nuget/dt/SmallSharp?color=darkmagenta)](https://www.nuget.org/packages/SmallSharp) [![License](https://img.shields.io/github/license/devlooped/SmallSharp.svg?color=blue)](https://github.com/devlooped/SmallSharp/blob/main/LICENSE) [![GH CI Status](https://github.com/devlooped/SmallSharp/workflows/build/badge.svg?branch=main)](https://github.com/devlooped/avatar/actions?query=branch%3Amain+workflow%3Abuild+)
55

6-
![Icon](https://raw.githubusercontent.com/devlooped/SmallSharp/main/assets/img/SmallSharpDemo.gif)
7-
86
<!-- #content -->
97
Create, edit and run multiple C# top-level programs in the same project 😍
108

119
## Why
1210

13-
The new-ish C# [top-level programs](https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/program-structure/top-level-statements)
11+
C# [top-level programs](https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/program-structure/top-level-statements)
1412
allow a very intuitive, simple and streamlined experience for quickly spiking or learning C#.
1513

1614
One missing thing since their introduction in Visual Studio is that you can only have one such
@@ -41,17 +39,14 @@ There is no need to install any Visual Studio extension. SmallSharp works by jus
4139

4240
![New Project Dialog](https://raw.githubusercontent.com/devlooped/SmallSharp/main/assets/img/NewConsoleProject.png)
4341

44-
By default, this new console project may not be set up to target `net5.0` or use the latest C# version.
45-
So click on the project node, and the project file will open in the editor. Make sure you either:
46-
47-
* Target the recommended framework version (i.e. net6.0):
42+
* Target the recommended framework version (i.e. net8.0 or net10.0):
4843

4944
```xml
5045
<Project Sdk="Microsoft.NET.Sdk">
5146

5247
<PropertyGroup>
5348
<OutputType>Exe</OutputType>
54-
<TargetFramework>net6.0</TargetFramework>
49+
<TargetFramework>net8.0</TargetFramework>
5550
</PropertyGroup>
5651

5752
</Project>
@@ -107,15 +102,12 @@ WriteLine("Hello World!");
107102
```
108103

109104
Keep adding as many top-level programs as you need, and switch between them easily by simply
110-
changing the active document.
111-
112-
![Demo](https://raw.githubusercontent.com/devlooped/SmallSharp/main/assets/img/TrackSelection.gif)
113-
105+
selecting the desired file from the Start button dropdown.
114106

115107
## How It Works
116108

117109
This nuget package leverages in concert the following standalone and otherwise
118-
unrelated features of the compiler, nuget, Visual Studio and MSBuild:
110+
unrelated features of the compiler, nuget and MSBuild:
119111

120112
1. The C# compiler only allows one top-level program per compilation.
121113
2. Launch profiles (the entries in the Run dropdown) are populated from the Properties\launchSettings.json file
@@ -127,8 +119,7 @@ unrelated features of the compiler, nuget, Visual Studio and MSBuild:
127119

128120
Using the above features in concert, **SmallSharp** essentially does the following:
129121

130-
* Monitor the active document in VS and emit it as a `launchSettings.json` profile and set it as
131-
the `$(ActiveDebugProfile)`.
122+
* Emit top-level files as a `launchSettings.json` profile and set the `$(ActiveDebugProfile)`.
132123

133124
* Exclude `.cs` files at the project level from being included as `<Compile>` by the default SDK
134125
includes and include them explicitly as `<None>` instead so they show up in the solution explorer.
@@ -139,16 +130,6 @@ Using the above features in concert, **SmallSharp** essentially does the followi
139130
This basically mean that this it will also work consistently if you use `dotnet run` from the command-line,
140131
since the "Main" file selection is performed exclusively via MSBuild item manipulation.
141132

142-
Finally, there is some lovely COM-based magic to access the active Visual Studio IDE (via DTE) to monitor
143-
the currently opened source file to keep it in sync with the launch profile. This is done purely using
144-
public COM primitives and equally public VSSDK nuget packages their APIs. This enables some useful integration
145-
with the IDE without requiring installing a VS extension from the marketplace and deal with gracefully
146-
degrading functionality.
147-
148-
> NOTE: If active document tracking fails to initialize properly restarting Visual Studio will almost
149-
> always fix it. Once tracking starts, it will work consistently from that point on. The Start dropdown
150-
> is always available as a fallback in case of issues.
151-
152133
<!-- include https://github.com/devlooped/sponsors/raw/main/footer.md -->
153134
# Sponsors
154135

src/SmallSharp/ActiveDocumentMonitor.cs

Lines changed: 0 additions & 260 deletions
This file was deleted.

src/SmallSharp/DisposableAction.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)