Skip to content

Commit

Permalink
Added new debug target to echo paths
Browse files Browse the repository at this point in the history
  • Loading branch information
ByronMayne committed Dec 3, 2023
1 parent 76a6377 commit 69dd181
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 6 deletions.
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,33 @@ When your source generator runs it needs to find it's dependencies and this is o

![AssemblyResolver](./img/AssemblyLoading.jpg)

You can embed any assemblies you want by adding them to `<SGF_EmbeddedAssembly Include="Your Assembly Path"/>`
You can embed any assemblies you want by adding them to `<SGF_EmbeddedAssembly Include="Your Assembly Path"/>`


## Project Layout

This library is made up of quite a few different components leveraging various techniques to help
make the experience of integrating the library simple. Below I break down the purpose of each project and what they provide to you as the end users.

### Source.Generator.Foundations

A very small library that only appears to contain a C# analyzer for adding errors and warnings when trying to use this library. However once compiled this dll will have embedded as a resource every other project that is needed during compilation.


### Source.Generator.Foundations.Contracts

Contains common classes and utility methods that can be leveraged by source generators.

### Source.Generator.Foundations.Injector

Uses `Mono.Cecil` to inject a static call to the `AssemblyResolver` to initialize as soon as the module is loaded. This same effect could be achieved using the `[ModuleInitialize]` attribute. However, this has two downsides. One, if other classes in the referencing project also use this attribute, the order of loading will not be known. Two, this attribute is not part of .netStandard so it has to be injected, there is a chance of conflict.



### Source.Generator.Foundations.MSBuild

Contains a custom MSBuild C# target implementation used to figure out which assemblies should be embedded as resources and which should be ignored. For example this will not embed any resources that are part of `.netstandard`.

### Source.Generator.Foundations.Shared

A shared project that every project that references this will have the files copied to it.
10 changes: 10 additions & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<Nullable>enable</Nullable>
<LangVersion>10</LangVersion>
<RootNamespace>SGF</RootNamespace>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<!--- Paths -->
<SGFSourceDir>$(MSBuildThisFileDirectory)</SGFSourceDir>

Expand All @@ -27,4 +28,13 @@
<SGFWindowsPluginProjectDir>$(SGFSourceDir)Plugins\SourceGenerator.Foundations.Windows\</SGFWindowsPluginProjectDir>
<SGFWindowsPluginProjectPath>$(SGFWindowsPluginProjectDir)SourceGenerator.Foundations.Windows.csproj</SGFWindowsPluginProjectPath>
</PropertyGroup>
<!-- Debug Targets -->
<Target Name="PrintSGFPaths">
<Message Importance="high" Text="SGFProjectDir: $(SGFProjectDir)"/>
<Message Importance="high" Text="SGFSharedProjectDir: $(SGFSharedProjectDir)"/>
<Message Importance="high" Text="SGFContractsProjectDir: $(SGFContractsProjectDir)"/>
<Message Importance="high" Text="SGFInjectorProjectDir: $(SGFInjectorProjectDir)"/>
<Message Importance="high" Text="SGFMSBuildProjectDir: $(SGFMSBuildProjectDir)"/>
<Message Importance="high" Text="SGFWindowsPluginProjectDir: $(SGFWindowsPluginProjectDir)"/>
</Target>
</Project>
5 changes: 3 additions & 2 deletions src/Nuget.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

<!-- Changes the content of the nuget package by manually adding files-->
<Target Name="AppendNugetContent">
<Message Importance="high" Text="Importing: $(SGFInjectorProjectPath)bin\$(Configuration)\net6.0\*.*"/>
<ItemGroup>
<TfmSpecificPackageFile Include="$(SGFContractsProjectDir)bin\$(Configuration)\netstandard2.0\SourceGenerator.Foundations.Contracts.dll">
<PackagePath>lib/netstandard2.0/SourceGenerator.Foundations.Contracts.dll</PackagePath>
Expand All @@ -30,8 +31,8 @@
<TfmSpecificPackageFile Include="$(SGFMSBuildProjectDir)bin\$(Configuration)netstandard2.0\SourceGenerator.Foundations.MSBuild.*">
<PackagePath>sgf/injector/</PackagePath>
</TfmSpecificPackageFile>
<TfmSpecificPackageFile Include="$(SGFInjectorProjectPath)bin\$(Configuration)\net6.0\*.*">
<PackagePath>build/</PackagePath>
<TfmSpecificPackageFile Include="$(SGFInjectorProjectDir)bin\$(Configuration)\net6.0\**\*.*">
<PackagePath>build</PackagePath>
</TfmSpecificPackageFile>
</ItemGroup>
</Target>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using EnvDTE;
using SGF.Diagnostics;
using System;
using System.Linq;
using System.Diagnostics;
using System.IO;
using Constants = EnvDTE.Constants;
Expand Down Expand Up @@ -52,10 +53,17 @@ internal VisualStudioLogEventSink()
m_buildOutput = pane;
}
}
// Store the currently active window, because adding a new one always draws focus, we don't want that
OutputWindowPane currentActive = m_outputWindow.ActivePane;

m_sourceGeneratorOutput ??= m_outputWindow.OutputWindowPanes.Add(outputPanelName);
currentActive.Activate(); // Set previous one to active

// When adding a pane will will steal focus, we don't want this. So lets force it back to build
foreach(OutputWindowPane pane in m_outputWindow.OutputWindowPanes)
{
if(string.Equals(BUILD_OUTPUT_PANE_GUID, pane.Guid))
{
pane.Activate();
}
}
}
}
catch
Expand Down

0 comments on commit 69dd181

Please sign in to comment.