Skip to content

Commit 9138c25

Browse files
committed
Refactor approach so it works better
We can't really detect the top-level programs first, because by that point, Roslyn already knows about the multiple files containing them and will show error squiglies in the IDE which are quite disconcerting when things actually do compile fine later on. So instead, we collect all top-level C# files (that is, not within a subfolder) and assume those will be the top-level programs. We add them all as launch profiles, and then before compile we remove all the Compile items which don't match the active debug profile selected. This works much better, even if intellisense is only on for the file which is selected in the dropdown, even if it's not the active one in the editor. Making both match will likely require IDE extensibility, so it's out of scope (for now?).
1 parent 7c3394c commit 9138c25

14 files changed

+96
-168
lines changed

.gitignore

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@ obj
88
*.lock.json
99
*.nuget.props
1010
*.nuget.targets
11+
dotnet-nugetize.items
1112
*.suo
1213
*.user
1314
*.cache
1415
*.log
1516
*.binlog
16-
*.rsp
17-
/src/Usage
18-
/src/Backup
19-
/src/TestResults
17+
*.rsp

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
![Icon](img/icon-32.png) SmallSharp
2+
============
3+
4+
Create, edit and run multiple C# 9.0 top-level programs
5+
in the same project by just selecting the startup program from the start
6+
button!
7+
8+
![Icon](img/launchSettings.png)
9+
10+
[![Version](https://img.shields.io/nuget/v/SmallSharp.svg?color=royalblue)](https://www.nuget.org/packages/SmallSharp)
11+
[![Downloads](https://img.shields.io/nuget/dt/SmallSharp.svg?color=green)](https://www.nuget.org/packages/SmallSharp)
12+
[![License](https://img.shields.io/github/license/kzu/SmallSharp.svg?color=blue)](https://github.com//kzu/SmallSharp/blob/main/LICENSE)
13+
[![Build](https://github.com/kzu/SmallSharp/workflows/build/badge.svg?branch=main)](https://github.com/kzu/SmallSharp/actions)
14+
15+
The new C# 9 [top-level programs](https://devblogs.microsoft.com/dotnet/welcome-to-c-9-0/#top-level-programs) allow a very intuitive, simple and streamlined experience for quickly spiking or learning C#.
16+
17+
> As of Visual Studio 16.8 Preview, you need to turn on this feature by adding this property to your project file:
18+
19+
```xml
20+
<LangVersion>Preview</LangVersion>
21+
```
22+
23+
24+
One missing thing in its current incarnation in Visual Studio 16.8 is that you can only have one such top-level programs in a project. This means that in order to prototype or learn a different area of .NET, you'd be forced to either replace your previous top-level program or change it to be a non-compile item somehow so you can keep it around (i.e. rename to a `.txt`).
25+
26+
**SmallSharp** brings that very feature by automatically generating a launch profile for each `.cs` file at the project level:
27+
28+
29+
This list is automatically kept in sync as you add more `.cs` files to the project. When you select one target C# file, that becomes the only top-level program to be compiled, so you don't have to modify any of the others since they automatically become *None* items.
30+
31+
All compile files directly under the project directory root are considered top-level programs for selection and compilation purposes. If you need to share code among them, you can place them in subdirectories and those will behave like normal compile items.
32+
33+
![Demo](img/SmallSharp.gif)

SmallSharp.sln

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
1919
.github\workflows\release.yml = .github\workflows\release.yml
2020
EndProjectSection
2121
EndProject
22-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SmallSharp.Build", "src\SmallSharp.Build\SmallSharp.Build.csproj", "{011AD1CC-2613-42D7-9BEF-0872F6409325}"
23-
EndProject
2422
Global
2523
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2624
Debug|Any CPU = Debug|Any CPU
@@ -31,10 +29,6 @@ Global
3129
{F87C7A13-669C-4F18-9266-B256F254DFA3}.Debug|Any CPU.Build.0 = Debug|Any CPU
3230
{F87C7A13-669C-4F18-9266-B256F254DFA3}.Release|Any CPU.ActiveCfg = Release|Any CPU
3331
{F87C7A13-669C-4F18-9266-B256F254DFA3}.Release|Any CPU.Build.0 = Release|Any CPU
34-
{011AD1CC-2613-42D7-9BEF-0872F6409325}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
35-
{011AD1CC-2613-42D7-9BEF-0872F6409325}.Debug|Any CPU.Build.0 = Debug|Any CPU
36-
{011AD1CC-2613-42D7-9BEF-0872F6409325}.Release|Any CPU.ActiveCfg = Release|Any CPU
37-
{011AD1CC-2613-42D7-9BEF-0872F6409325}.Release|Any CPU.Build.0 = Release|Any CPU
3832
EndGlobalSection
3933
GlobalSection(SolutionProperties) = preSolution
4034
HideSolutionNode = FALSE

img/SmallSharp.gif

3.06 MB
Loading

img/launchSettings.png

11.5 KB
Loading

src/Directory.Build.targets

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,7 @@
2424
</PropertyGroup>
2525

2626
<ItemGroup>
27-
<!--<None Update="@(None)" Pack="true" CopyToOutputDirectory="PreserveNewest" />-->
2827
<_PackageFiles Include="$(MSBuildThisFileDirectory)_._" PackagePath="lib/netstandard2.0/_._" />
29-
30-
<!--<EmbeddedResource Include="@(None -&gt; WithMetadataValue('Extension', '.sbntxt'))" />-->
31-
32-
<!--<_PackageFiles Include="@(None -&gt; WithMetadataValue('Extension', '.sbntxt'))" PackagePath="$(BuildOutputTargetFolder)/$(TargetFramework)/%(Filename)%(Extension)" />-->
33-
<!--<_PackageFiles Include="*.props" PackagePath="build/$(TargetFramework)" />
34-
<_PackageFiles Include="*.targets" PackagePath="build/$(TargetFramework)" />-->
35-
3628
<UpToDateCheck Include="@(EmbeddedResource);@(_PackageFiles);@(None)" />
3729
</ItemGroup>
3830

@@ -87,25 +79,4 @@ Built from $(RepositoryUrl)/tree/$(SourceRevisionId.Substring(0, 9))
8779
<Exec Command='rm -rf "$(HttpNuGetCache)"' Condition="'$(OS)' != 'Windows_NT'" />
8880
</Target>
8981

90-
<!-- For every PackageReference with Pack=true, we include the assemblies from it in the package -->
91-
<Target Name="AddPackDependencies" Condition="'' != ''" Inputs="@(RuntimeCopyLocalItems)" Outputs="%(RuntimeCopyLocalItems.NuGetPackageId)" AfterTargets="ResolvePackageAssets">
92-
<ItemGroup>
93-
<NuGetPackageId Include="@(RuntimeCopyLocalItems -> '%(NuGetPackageId)')" />
94-
</ItemGroup>
95-
<PropertyGroup>
96-
<NuGetPackageId>@(NuGetPackageId -&gt; Distinct())</NuGetPackageId>
97-
</PropertyGroup>
98-
<ItemGroup>
99-
<PackageReferenceDependency Include="@(PackageReference -&gt; WithMetadataValue('Identity', '$(NuGetPackageId)'))" />
100-
</ItemGroup>
101-
<PropertyGroup>
102-
<NuGetPackagePack>@(PackageReferenceDependency -> '%(Pack)')</NuGetPackagePack>
103-
</PropertyGroup>
104-
<ItemGroup Condition="'$(NuGetPackagePack)' == 'true'">
105-
<_PackageFiles Include="@(RuntimeCopyLocalItems)" PackagePath="$(BuildOutputTargetFolder)/$(TargetFramework)/%(Filename)%(Extension)" />
106-
<RuntimeCopyLocalItems Update="@(RuntimeCopyLocalItems)" CopyLocal="true" Private="true" />
107-
<ResolvedFileToPublish Include="@(RuntimeCopyLocalItems)" CopyToPublishDirectory="PreserveNewest" RelativePath="%(Filename)%(Extension)" />
108-
</ItemGroup>
109-
</Target>
110-
11182
</Project>

src/SmallSharp.Build/JsonPeek.cs

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

src/SmallSharp.Build/SmallSharp.Build.csproj

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

src/SmallSharp.Build/SmallSharp.Build.targets

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

src/SmallSharp/GeneratorExtension.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using System;
2-
using System.Diagnostics;
3-
using System.IO;
4-
using System.Text;
1+
using System.Diagnostics;
52
using Microsoft.CodeAnalysis;
63

74
namespace SmallSharp

0 commit comments

Comments
 (0)