Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ env:
ProjectDir: src\SourceGenerator.Foundations\
ProjectName: SourceGenerator.Foundations.csproj
SolutionPath: src\SourceGenerator.Foundations.sln
MSBUILDDISABLENODEREUSE: '1' # Stops MSBuild from locking MSBuild nuget package
jobs:
build:
name: Build | All
Expand All @@ -36,7 +35,6 @@ jobs:
- name: SourceGenerator.Foundations.Tests
- name: ConsoleApp.SourceGenerator.Tests
path: Sandbox/
- name: SourceGenerator.Foundations.MSBuild.Tests
steps:
- uses: actions/checkout@v3
with:
Expand Down
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ This works well but requires a lot of boilerplate. Even worse is this is just fo

*Source.Generator foundations automates this all for you. Just add your NuGet references and nothing else*

By default, SGF does **not** embed `Microsoft.CodeAnalysis.*` assemblies. Roslyn is provided by the compiler/IDE host at runtime, so embedding those assemblies can cause type identity conflicts and broken design-time behavior.
By default, SGF does **not** embed `Microsoft.CodeAnalysis.*` assemblies. Roslyn is provided by the compiler/IDE host at runtime, so embedding those assemblies can cause type identity conflicts and broken design-time behavior. This behavior is controlled through the `SGFExcludeAssemblyName` MSBuild item.

## Logging Framework
Source generator run in the background and it can be very hard to debug. If you want to make a log you have to write the files to disk and open to read them.
Expand Down Expand Up @@ -214,20 +214,23 @@ When your source generator runs it needs to find it's dependencies and this is o

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

`Microsoft.CodeAnalysis.*` assemblies are excluded from SGF dependency embedding by default. If you need the previous behavior, opt in explicitly:
`Microsoft.CodeAnalysis.*` assemblies are excluded from SGF dependency embedding by default using `SGFExcludeAssemblyName`.

To exclude additional assemblies from embedding, add to `SGFExcludeAssemblyName`:

```xml
<PropertyGroup>
<SGFEmbedCodeAnalysis>true</SGFEmbedCodeAnalysis>
</PropertyGroup>
<ItemGroup>
<SGFExcludeAssemblyName Include="My.Host.Provided.Dependency" />
<SGFExcludeAssemblyName Include="Company.Shared.Utility.dll" />
</ItemGroup>
```

You can also exclude additional assemblies by name (with optional wildcard support):
If you want to embed Roslyn assemblies anyway, remove the default exclusions in your project:

```xml
<ItemGroup>
<SGFExcludedAssembly Include="My.Host.Provided.Dependency" />
<SGFExcludedAssembly Include="Company.Shared.*" />
<SGFExcludeAssemblyName Remove="Microsoft.CodeAnalysis" />
<SGFExcludeAssemblyName Remove="Microsoft.CodeAnalysis.CSharp" />
</ItemGroup>
```

Expand Down
10 changes: 3 additions & 7 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,19 @@
<!-- Paths | SGF Core -->
<SGFProjectDir>$(SGFSourceDir)SourceGenerator.Foundations\</SGFProjectDir>
<SGFProjectPath>$(SGFProjectDir)SourceGenerator.Foundations.csproj</SGFProjectPath>
<SGFTargetsPath>$(SGFProjectDir)SourceGenerator.Foundations.targets</SGFTargetsPath>
<SGFPropsPath>$(SGFProjectDir)SourceGenerator.Foundations.props</SGFPropsPath>
<SGFTargetsPath>$(SGFProjectDir)Build\SourceGenerator.Foundations.targets</SGFTargetsPath>
<SGFPropsPath>$(SGFProjectDir)Build\SourceGenerator.Foundations.props</SGFPropsPath>
<!-- Paths | SGF Shared -->

<SGFSharedProjectDir>$(SGFSourceDir)SourceGenerator.Foundations.Shared\</SGFSharedProjectDir>
<SGFSharedProjectItemsPath>$(SGFSharedProjectDir)SourceGenerator.Foundations.Shared.projitems</SGFSharedProjectItemsPath>
<!-- Paths | SGF Contracts -->
<SGFContractsProjectDir>$(SGFSourceDir)SourceGenerator.Foundations.Contracts\</SGFContractsProjectDir>
<SGFContractsProjectPath>$(SGFContractsProjectDir)SourceGenerator.Foundations.Contracts.csproj</SGFContractsProjectPath>
<!-- Paths | SGF MSBuild -->
<SGFMSBuildProjectDir>$(SGFSourceDir)SourceGenerator.Foundations.MSBuild\</SGFMSBuildProjectDir>
<SGFMSBuildProjectPath>$(SGFMSBuildProjectDir)SourceGenerator.Foundations.MSBuild.csproj</SGFMSBuildProjectPath>
<!-- Paths | SGF Plugin Window -->
<SGFWindowsPluginProjectDir>$(SGFSourceDir)Plugins\SourceGenerator.Foundations.Windows\</SGFWindowsPluginProjectDir>
<SGFWindowsPluginProjectPath>$(SGFWindowsPluginProjectDir)SourceGenerator.Foundations.Windows.csproj</SGFWindowsPluginProjectPath>

<!-- Local Path Overrides | Both a local build and the nuget package use the same logic. This is used to override the paths when building locally -->
<SGFMsBuildPath>$(LibsDir)SourceGenerator.Foundations.MSBuild\SourceGenerator.Foundations.MSBuild.dll</SGFMsBuildPath>
</PropertyGroup>
<!-- Debug Targets -->
<Target Name="PrintSGFPaths">
Expand Down
4 changes: 2 additions & 2 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<PackageVersion Include="coverlet.collector" Version="6.0.0" />
<PackageVersion Include="envdte" Version="17.4.33103.184" />
<PackageVersion Include="Handlebars.Net" Version="2.1.3" />
<PackageVersion Include="Microsoft.Build.Framework" Version="17.8.3" />
<PackageVersion Include="Microsoft.Build.Utilities.Core" Version="17.8.3" />
<PackageVersion Include="Microsoft.Build.Framework" Version="18.7.1" />
<PackageVersion Include="Microsoft.Build.Utilities.Core" Version="18.7.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="4.3.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.3.1" />
Expand Down
23 changes: 23 additions & 0 deletions src/Sandbox/ConsoleApp.SourceGenerator.Tests/ResourceTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using ConsoleApp.SourceGenerator;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace SGF
{
public class ResourceTests
{
[Theory]
[InlineData("SGF.Assembly::Microsoft.CodeAnalysis.dll")]
[InlineData("SGF.Assembly::Microsoft.CodeAnalysis.CSharp.dll")]
public void Assembly_Does_Not_Contain_Resource(string resourceName)
{
Assembly assembly = typeof(ConsoleAppSourceGeneratorHoist).Assembly;
string[] resourceNames = assembly.GetManifestResourceNames();
Assert.DoesNotContain(resourceName, resourceNames);
}
}
}

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions src/SourceGenerator.Foundations.MSBuild.slnx

This file was deleted.

Loading
Loading