/// <summary> /// Create a compilation given source and reference assemblies /// </summary> /// <param name="source">Source to compile</param> /// <param name="referenceAssemblies">Reference assemblies to include</param> /// <param name="outputKind">Output type</param> /// <param name="allowUnsafe">Whether or not use of the unsafe keyword should be allowed</param> /// <returns>The resulting compilation</returns> public static async Task <Compilation> CreateCompilationWithReferenceAssemblies(SyntaxTree[] sources, ReferenceAssemblies referenceAssemblies, OutputKind outputKind = OutputKind.DynamicallyLinkedLibrary, bool allowUnsafe = true) { return(CSharpCompilation.Create("compilation", sources, (await referenceAssemblies.ResolveAsync(LanguageNames.CSharp, CancellationToken.None)), new CSharpCompilationOptions(outputKind, allowUnsafe: allowUnsafe))); }
public async static ValueTask <ImmutableArray <MetadataReference> > GetNet6References() { if (s_net6Refs.IsDefault) { var refs = await Net6PreviewAssemblies.ResolveAsync(null, default); ImmutableInterlocked.InterlockedInitialize(ref s_net6Refs, refs); } return(s_net6Refs); }
private static async Task <ImmutableArray <MetadataReference> > CreateReferenceAssembliesAsync() { ReferenceAssemblies referenceAssemblies = ReferenceAssemblies.Net.Net50; ImmutableArray <MetadataReference> references = await referenceAssemblies.ResolveAsync(LanguageNames.CSharp, CancellationToken.None); PortableExecutableReference xunit = MetadataReference.CreateFromFile(typeof(FactAttribute).Assembly.Location); PortableExecutableReference assert = MetadataReference.CreateFromFile(typeof(Assert).Assembly.Location); return(references.AddRange(new[] { xunit, assert })); }
private static async Task <ImmutableArray <MetadataReference> > ResolveReferenceAssemblies(ReferenceAssemblies referenceAssemblies) { try { ResolveRedirect.Instance.Start(); return(await referenceAssemblies.ResolveAsync(LanguageNames.CSharp, CancellationToken.None)); } finally { ResolveRedirect.Instance.Stop(); } }
private static async Task <ImmutableArray <MetadataReference> > ResolveReferenceAssemblies(ReferenceAssemblies referenceAssemblies) { try { ResolveRedirect.Instance.Start(); return(await referenceAssemblies.ResolveAsync(LanguageNames.CSharp, CancellationToken.None)); } catch (Exception e) { ThrowSkipExceptionIfPackagingException(e); throw; } finally { ResolveRedirect.Instance.Stop(); } }
public async Task InitializeAsync() { ReferenceAssemblies references = ReferenceAssemblies.NetStandard.NetStandard20 .AddPackages(ImmutableArray.Create( new PackageIdentity("System.Memory", "4.5.4"), new PackageIdentity("Microsoft.Windows.SDK.Contracts", "10.0.19041.1"))); ImmutableArray <MetadataReference> metadataReferences = await references.ResolveAsync(LanguageNames.CSharp, default); // Workaround for https://github.com/dotnet/roslyn-sdk/issues/699 metadataReferences = metadataReferences.AddRange( Directory.GetFiles(Path.Combine(Path.GetTempPath(), "test-packages", "Microsoft.Windows.SDK.Contracts.10.0.19041.1", "ref", "netstandard2.0"), "*.winmd").Select(p => MetadataReference.CreateFromFile(p))); // CONSIDER: How can I pass in the source generator itself, with AdditionalFiles, so I'm exercising that code too? this.compilation = CSharpCompilation.Create( assemblyName: "test", references: metadataReferences, options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, allowUnsafe: true)); }