diff --git a/README.md b/README.md
index 20b1e5a..2df79e6 100644
--- a/README.md
+++ b/README.md
@@ -1,16 +1,17 @@
# Bakery
+
[![NuGet](https://img.shields.io/nuget/v/Cake.Bakery.svg)](https://www.nuget.org/packages/Cake.Bakery)
[![MyGet](https://img.shields.io/myget/cake/vpre/Cake.Bakery.svg?label=myget)](https://www.myget.org/gallery/cake)
-Cake server for code generation and script analysis
+Cake server for code generation and script analysis, used for i.e. intellisense support in Visual Studio Code.
## Build Status
-|Build server|Platform|Develop|Master|
-|:--:|:--:|:--:|:--:|
-|AppVeyor|Windows|[![Build status](https://ci.appveyor.com/api/projects/status/ayjo26v8rbhp2eqt/branch/develop?svg=true)](https://ci.appveyor.com/project/cakebuild/bakery/branch/develop)|[![Build status](https://ci.appveyor.com/api/projects/status/ayjo26v8rbhp2eqt/branch/develop?svg=true)](https://ci.appveyor.com/project/cakebuild/bakery/branch/master)|
-|Bitrise|OS X|[![Build Status](https://www.bitrise.io/app/000857f04ffa750e/status.svg?token=B72wRhe84cgWLCI5k_dgNw&branch=develop)](https://www.bitrise.io/app/000857f04ffa750e)|[![Build Status](https://www.bitrise.io/app/000857f04ffa750e/status.svg?token=B72wRhe84cgWLCI5k_dgNw&branch=master)](https://www.bitrise.io/app/000857f04ffa750e)|
-|Bitrise|Linux|[![Build Status](https://www.bitrise.io/app/704fc45fd74ac20f/status.svg?token=TnnmPBUFK5KISi5WhME5MQ&branch=develop)](https://www.bitrise.io/app/704fc45fd74ac20f)|[![Build Status](https://www.bitrise.io/app/704fc45fd74ac20f/status.svg?token=TnnmPBUFK5KISi5WhME5MQ&branch=master)](https://www.bitrise.io/app/704fc45fd74ac20f)|
+| Build server | Platform | Develop| Master |
+|-------------------|:-------------:|:------:|:------:|
+| AppVeyor | Windows | [![Build status](https://ci.appveyor.com/api/projects/status/ayjo26v8rbhp2eqt/branch/develop?svg=true)](https://ci.appveyor.com/project/cakebuild/bakery/branch/develop) | [![Build status](https://ci.appveyor.com/api/projects/status/ayjo26v8rbhp2eqt/branch/develop?svg=true)](https://ci.appveyor.com/project/cakebuild/bakery/branch/master)|
+| GitHub Actions | Windows | [![Build status](https://github.com/cake-build/bakery/actions/workflows/build.yml/badge.svg?branch=develop)](https://github.com/cake-build/bakery/actions/workflows/build.yml) | [![Build status](https://github.com/cake-build/bakery/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/cake-build/bakery/actions/workflows/build.yml) |
+| GitHub Actions | macOS / Linux | [![Posix Build status](https://github.com/cake-build/bakery/actions/workflows/posixbuild.yml/badge.svg?branch=develop)](https://github.com/cake-build/bakery/actions/workflows/posixbuild.yml) | [![Posix Build status](https://github.com/cake-build/bakery/actions/workflows/posixbuild.yml/badge.svg?branch=master)](https://github.com/cake-build/bakery/actions/workflows/posixbuild.yml) |
## Code of Conduct
diff --git a/src/Cake.Scripting/Cake.Scripting.csproj b/src/Cake.Scripting/Cake.Scripting.csproj
index 7782b09..a7a6ba1 100644
--- a/src/Cake.Scripting/Cake.Scripting.csproj
+++ b/src/Cake.Scripting/Cake.Scripting.csproj
@@ -15,6 +15,7 @@
+
diff --git a/src/Cake.Scripting/CodeGen/CakeScriptGenerator.cs b/src/Cake.Scripting/CodeGen/CakeScriptGenerator.cs
index a6eedfa..c3efa6b 100644
--- a/src/Cake.Scripting/CodeGen/CakeScriptGenerator.cs
+++ b/src/Cake.Scripting/CodeGen/CakeScriptGenerator.cs
@@ -39,9 +39,10 @@ public sealed class CakeScriptGenerator : IScriptGenerationService
private readonly IBufferedFileSystem _fileSystem;
private readonly IScriptAliasFinder _aliasFinder;
private readonly ICakeAliasGenerator _aliasGenerator;
+ private readonly IScriptConventions _scriptConventions;
+ private readonly IReferenceAssemblyResolver _referenceAssemblyResolver;
private readonly DirectoryPath _addinRoot;
private readonly ScriptHost _hostObject;
- private readonly Lazy> _defaultReferences;
public CakeScriptGenerator(
IBufferedFileSystem fileSystem,
@@ -52,6 +53,8 @@ public CakeScriptGenerator(
IScriptAliasFinder aliasFinder,
ICakeAliasGenerator aliasGenerator,
ICakeLog log,
+ IScriptConventions scriptConventions,
+ IReferenceAssemblyResolver referenceAssemblyResolver,
IEnumerable loadDirectiveProviders = null)
{
_fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
@@ -63,10 +66,11 @@ public CakeScriptGenerator(
_aliasFinder = aliasFinder ?? throw new ArgumentNullException(nameof(aliasFinder));
_aliasGenerator = aliasGenerator ?? throw new ArgumentNullException(nameof(aliasGenerator));
_analyzer = new ScriptAnalyzer(_fileSystem, _environment, _log, loadDirectiveProviders);
+ _scriptConventions = scriptConventions ?? throw new ArgumentNullException(nameof(scriptConventions));
+ _referenceAssemblyResolver = referenceAssemblyResolver ?? throw new ArgumentNullException(nameof(referenceAssemblyResolver));
_addinRoot = GetAddinPath(_environment.WorkingDirectory);
_hostObject = GetHostObject();
- _defaultReferences = new Lazy>(GetDefaultReferences);
}
public CakeScript Generate(FileChange fileChange)
@@ -111,7 +115,12 @@ public CakeScript Generate(FileChange fileChange)
// Load all references.
_log.Verbose("Adding references...");
- var references = new HashSet(_defaultReferences.Value);
+ var references = new HashSet(
+ _scriptConventions
+ .GetDefaultAssemblies(_environment.ApplicationRoot)
+ .Union(_referenceAssemblyResolver.GetReferenceAssemblies())
+ .Select(a => FilePath.FromString(a.Location)));
+
references.AddRange(result.References.Select(r => new FilePath(r)));
// Find aliases
@@ -128,7 +137,7 @@ public CakeScript Generate(FileChange fileChange)
// Import all namespaces.
_log.Verbose("Importing namespaces...");
var namespaces = new HashSet(result.Namespaces, StringComparer.Ordinal);
- namespaces.AddRange(GetDefaultNamespaces());
+ namespaces.AddRange(_scriptConventions.GetDefaultNamespaces());
namespaces.AddRange(aliases.SelectMany(alias => alias.Namespaces));
// Create the response.
@@ -165,48 +174,6 @@ private void HandleFileChange(FilePath path, FileChange fileChange)
_fileSystem.UpdateFileBuffer(path, fileChange.Buffer);
}
- // TODO: Move to conventions
- private IEnumerable GetDefaultNamespaces()
- {
- return new List
- {
- "System",
- "System.Collections.Generic",
- "System.Linq",
- "System.Text",
- "System.Threading.Tasks",
- "System.IO",
- "Cake.Core",
- "Cake.Core.IO",
- "Cake.Core.Scripting",
- "Cake.Core.Diagnostics"
- };
- }
-
- private ISet GetDefaultReferences()
- {
- // Prepare the default assemblies.
- var references = new HashSet();
- references.Add(typeof(Action).GetTypeInfo().Assembly.Location); // mscorlib or System.Private.Core
- references.Add(typeof(IQueryable).GetTypeInfo().Assembly.Location); // System.Core or System.Linq.Expressions
-
- references.Add(typeof(IScriptHost).Assembly.Location); // Cake.Core
- references.Add(typeof(EnvironmentAliases).Assembly.Location); // Cake.Common
-
- references.Add(typeof(Uri).GetTypeInfo().Assembly.Location); // System
- references.Add(typeof(Enumerable).GetTypeInfo().Assembly.Location); // System.Linq
- references.Add(typeof(XmlReader).GetTypeInfo().Assembly.Location); // System.Xml
- references.Add(typeof(XDocument).GetTypeInfo().Assembly.Location); // System.Xml.Linq
- references.Add(typeof(DataTable).GetTypeInfo().Assembly.Location); // System.Data
- references.Add(typeof(ZipArchive).GetTypeInfo().Assembly.Location); // System.IO.Compression
- references.Add(typeof(ZipFile).GetTypeInfo().Assembly.Location); // System.IO.Compression.FileSystem
- references.Add(typeof(HttpClient).GetTypeInfo().Assembly.Location); // System.Net.Http
- references.Add(typeof(DataContractJsonSerializer).GetTypeInfo().Assembly.Location); // System.Runtime.Serialization
-
- // Return the assemblies.
- return references;
- }
-
private static ScriptHost GetHostObject()
{
return new ScriptHost
diff --git a/src/Cake.Scripting/Polyfill/IReferenceAssemblyResolver.cs b/src/Cake.Scripting/Polyfill/IReferenceAssemblyResolver.cs
new file mode 100644
index 0000000..675fcdf
--- /dev/null
+++ b/src/Cake.Scripting/Polyfill/IReferenceAssemblyResolver.cs
@@ -0,0 +1,19 @@
+using System.Reflection;
+
+#pragma warning disable IDE0130
+// Temporary polyfill see https://github.com/cake-build/cake/pull/3715
+namespace Cake.Core.Scripting
+#pragma warning restore IDE0130
+{
+ ///
+ /// Represents a framework reference assembly resolver.
+ ///
+ public interface IReferenceAssemblyResolver
+ {
+ ///
+ /// Finds framwork reference assemblies.
+ ///
+ /// The resolved reference assemblies.
+ Assembly[] GetReferenceAssemblies();
+ }
+}
\ No newline at end of file
diff --git a/src/Cake.Scripting/Reflection/ReferenceAssemblyResolver.cs b/src/Cake.Scripting/Reflection/ReferenceAssemblyResolver.cs
new file mode 100644
index 0000000..5524852
--- /dev/null
+++ b/src/Cake.Scripting/Reflection/ReferenceAssemblyResolver.cs
@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using Cake.Core.Diagnostics;
+using Cake.Core.Scripting;
+
+namespace Cake.Scripting.Reflection
+{
+ public sealed class ReferenceAssemblyResolver : IReferenceAssemblyResolver
+ {
+ private readonly ICakeLog _log;
+
+ public ReferenceAssemblyResolver(ICakeLog log)
+ {
+ _log = log;
+ }
+
+ public Assembly[] GetReferenceAssemblies()
+ {
+ IEnumerable TryGetReferenceAssemblies()
+ {
+ foreach (var reference in Basic.Reference.Assemblies.Net60.All)
+ {
+ Assembly name;
+ try
+ {
+ name = Assembly.Load(System.IO.Path.GetFileNameWithoutExtension(reference.FilePath));
+ }
+ catch (Exception ex)
+ {
+ _log.Debug(log => log("Failed to load {0}\r\n{1}", reference.FilePath, ex));
+ continue;
+ }
+
+ yield return name;
+ }
+ }
+
+ return TryGetReferenceAssemblies().ToArray();
+ }
+ }
+}
diff --git a/src/Cake.Scripting/ScriptingModule.cs b/src/Cake.Scripting/ScriptingModule.cs
index 00453f5..6267eb3 100644
--- a/src/Cake.Scripting/ScriptingModule.cs
+++ b/src/Cake.Scripting/ScriptingModule.cs
@@ -10,6 +10,7 @@
using Cake.Scripting.CodeGen;
using Cake.Scripting.CodeGen.Generators;
using Cake.Scripting.IO;
+using Cake.Scripting.Reflection;
namespace Cake.Scripting
{
@@ -41,6 +42,7 @@ public void Register(ICakeContainerRegistrar registrar)
registrar.RegisterType().As().Singleton();
registrar.RegisterType().As().Singleton();
registrar.RegisterType().As().Singleton();
+ registrar.RegisterType().As().Singleton();
}
}
}