roslyn: VS doesn't support MSBuild property
Version Used: VS 17.3.0 Preview 1.1
Steps to Reproduce:
- Create a solution that has two projects: MyApp and MyGenerator.
- Make MyGenerator depend on a NuGet package, such as
Microsoft.OpenApi.Readers, and set<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>in the source generator’s.csprojfile.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
...
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.2.3" />
</ItemGroup>
</Project>
- Make MyApp use the source generator.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\MyGenerator\MyGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" SetTargetFramework="TargetFramework=netstandard2.0" />
</ItemGroup>
</Project>
- Build MyApp from the command line. Everything builds fine.
- Open VS. The generator fails to run, with this error:
Generator 'ControllerGenerator' failed to generate source.
It will not contribute to the output and compilation errors may occur as a result.
Exception was of type 'FileNotFoundException' with message 'Could not load file or assembly 'Microsoft.OpenApi.Readers, Version=1.2.3.0, Culture=neutral, PublicKeyToken=3f5743946376f042' or one of its dependencies. The system cannot find the file specified.'
Here’s an example project that reproduces the issue: https://github.com/Bosch-Eli-Black/source-generator-example
Expected Behavior:
VS supports <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
Actual Behavior:
VS appears to not yet support <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
Misc:
It would be super awesome if VS support the CopyLocalLockFileAssemblies property, because then we wouldn’t need to manually copy NuGet packages 🙂
Today, we need to do this:
<!-- See https://github.com/dotnet/roslyn-sdk/blob/0313c80ed950ac4f4eef11bb2e1c6d1009b328c4/samples/CSharp/SourceGenerators/SourceGeneratorSamples/SourceGeneratorSamples.csproj#L13-L30
and https://github.com/dotnet/roslyn/discussions/47517#discussioncomment-64145 -->
<PropertyGroup>
<GetTargetPathDependsOn>$(GetTargetPathDependsOn);GetDependencyTargetPaths</GetTargetPathDependsOn>
</PropertyGroup>
<Target Name="GetDependencyTargetPaths">
<!-- Manually include the DLL of each NuGet package that this analyzer uses. -->
<ItemGroup>
<TargetPathWithTargetPlatformMoniker Include="$(PKGGraphQL)\lib\netstandard2.0\GraphQL.dll" IncludeRuntimeDependency="false" />
</ItemGroup>
</Target>
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 6
- Comments: 16 (3 by maintainers)
Thanks, @jmarolf and @rainersigwald 🙂
The main issue is that if my analyzer/source-generator depends on a NuGet, I’d like for VS to automatically include the NuGet’s
.dll’s, so that I don’t need to manually include them 🙂Today, we have to do this:
Ideally, this would be automatic, so that when my analyzer references a NuGet, it’s
.dll’s automatically get included, so I just do this:I think this would be of great value, as it seems to be one of the primary stumbling blocks that developers new to source generators seem to encounter 🙂 (See https://github.com/dotnet/roslyn/discussions/47517, https://github.com/dotnet/roslyn/issues/60256#issuecomment-1131364519, https://github.com/dotnet/roslyn/issues/57997#issuecomment-1024601830, https://github.com/dotnet/roslyn/issues/52017#issuecomment-809113013, https://github.com/dotnet/roslyn/issues/50148, https://github.com/dotnet/roslyn/issues/49075, etc.)
yep, I need to write and SDK piece that does all the project and nuget reference resolution logic. It’s not trivial but I have had some success in early experiments. Unfortunately I don’t have an ETA
@alienriver49 Yes, you currently need to include all dependencies, so in your case, you’ll need to include
Namotion.Reflectionand any of its dependencies.@jmarolf Oh, yay! 🙂