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
7 changes: 7 additions & 0 deletions DotNetWorker.sln
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Worker.Extensions.Shared.Te
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Worker.Extensions.Http.AspNetCore.Analyzers", "extensions\Worker.Extensions.Http.AspNetCore.Analyzers\Worker.Extensions.Http.AspNetCore.Analyzers.csproj", "{7B6C2920-7A02-43B2-8DA0-7B76B9FAFC6B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Net7Worker", "samples\Net7Worker\Net7Worker.csproj", "{BE1F79C3-24FA-4BC8-BAB2-C1AD321B13FF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DependentAssemblyWithFunctions.NetStandard", "test\DependentAssemblyWithFunctions.NetStandard\DependentAssemblyWithFunctions.NetStandard.csproj", "{198DA072-F94F-4585-A744-97B3DAC21686}"
EndProject
Global
Expand Down Expand Up @@ -344,6 +346,10 @@ Global
{D8E79B53-9A44-46CC-9D7A-E9494FC8CAF4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D8E79B53-9A44-46CC-9D7A-E9494FC8CAF4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D8E79B53-9A44-46CC-9D7A-E9494FC8CAF4}.Release|Any CPU.Build.0 = Release|Any CPU
{BE1F79C3-24FA-4BC8-BAB2-C1AD321B13FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BE1F79C3-24FA-4BC8-BAB2-C1AD321B13FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BE1F79C3-24FA-4BC8-BAB2-C1AD321B13FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BE1F79C3-24FA-4BC8-BAB2-C1AD321B13FF}.Release|Any CPU.Build.0 = Release|Any CPU
{B6342174-5436-4846-B43C-39D8E34AE5CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B6342174-5436-4846-B43C-39D8E34AE5CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B6342174-5436-4846-B43C-39D8E34AE5CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -417,6 +423,7 @@ Global
{D8E79B53-9A44-46CC-9D7A-E9494FC8CAF4} = {AA4D318D-101B-49E7-A4EC-B34165AEDB33}
{B6342174-5436-4846-B43C-39D8E34AE5CF} = {FD7243E4-BF18-43F8-8744-BA1D17ACF378}
{7B6C2920-7A02-43B2-8DA0-7B76B9FAFC6B} = {A7B4FF1E-3DF7-4F28-9333-D0961CDDF702}
{BE1F79C3-24FA-4BC8-BAB2-C1AD321B13FF} = {9D6603BD-7EA2-4D11-A69C-0D9E01317FD6}
{198DA072-F94F-4585-A744-97B3DAC21686} = {B5821230-6E0A-4535-88A9-ED31B6F07596}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
Expand Down
10 changes: 10 additions & 0 deletions build/Sdk.slnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
Comment thread
jviau marked this conversation as resolved.
"solution": {
"path": "..\\DotNetWorker.sln",
"projects": [
"sdk\\Sdk.Analyzers\\Sdk.Analyzers.csproj",
"sdk\\Sdk.Generators\\Sdk.Generators.csproj",
"sdk\\Sdk\\Sdk.csproj"
]
}
}
3 changes: 2 additions & 1 deletion samples/FunctionApp/FunctionApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
<_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\key.snk</AssemblyOriginatorKeyFile>
<SdkVersion>1.17.2</SdkVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.17.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="$(SdkVersion)" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.Net.NameResolution" Version="4.3.0" />
</ItemGroup>
Expand Down
24 changes: 14 additions & 10 deletions sdk/Sdk/ExtensionsCsprojGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.Azure.Functions.Worker.Sdk
{
internal class ExtensionsCsprojGenerator
{
private const string ExtensionsProjectName = "WorkerExtensions.csproj";
internal const string ExtensionsProjectName = "WorkerExtensions.csproj";

private readonly IDictionary<string, string> _extensions;
private readonly string _outputPath;
Expand All @@ -31,9 +31,20 @@ public void Generate()
{
var extensionsCsprojFilePath = Path.Combine(_outputPath, ExtensionsProjectName);

RecreateDirectory(_outputPath);
string csproj = GetCsProjContent();
if (File.Exists(extensionsCsprojFilePath))
{
string existing = File.ReadAllText(extensionsCsprojFilePath);
if (string.Equals(csproj, existing, StringComparison.Ordinal))
{
// If contents are the same, only touch the file to update timestamp.
File.SetLastWriteTimeUtc(extensionsCsprojFilePath, DateTime.UtcNow);
return;
}
}

WriteExtensionsCsProj(extensionsCsprojFilePath);
RecreateDirectory(_outputPath);
File.WriteAllText(extensionsCsprojFilePath, csproj);
}

private void RecreateDirectory(string directoryPath)
Expand All @@ -46,13 +57,6 @@ private void RecreateDirectory(string directoryPath)
Directory.CreateDirectory(directoryPath);
}

private void WriteExtensionsCsProj(string filePath)
{
string csprojContent = GetCsProjContent();

File.WriteAllText(filePath, csprojContent);
}

internal string GetCsProjContent()
{
string extensionReferences = GetExtensionReferences();
Expand Down
32 changes: 11 additions & 21 deletions sdk/Sdk/FunctionMetadataGenerator.cs
Comment thread
jviau marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Dynamic;
using System.IO;
using System.Linq;
using Microsoft.Build.Framework;
using Mono.Cecil;
using Mono.Collections.Generic;

Expand Down Expand Up @@ -42,44 +43,33 @@ public IDictionary<string, string> Extensions
}
}

public IEnumerable<SdkFunctionMetadata> GenerateFunctionMetadata(string assemblyPath, IEnumerable<string> referencePaths)
public IEnumerable<SdkFunctionMetadata> GenerateFunctionMetadata(string assemblyPath, IEnumerable<ITaskItem> referencePaths)
{
string sourcePath = Path.GetDirectoryName(assemblyPath);
var targetAssemblies = new List<string>() { assemblyPath };

var targetAssemblies = new List<string>(Directory.GetFiles(sourcePath, "*.dll"));
// We don't need to scan assemblies that come from a framework (.NET, AspNetCore), they won't have functions types in them.
targetAssemblies.AddRange(referencePaths.Where(x => x.GetMetadata("FrameworkReferenceName") == "").Select(x => x.ItemSpec));
Comment thread
jviau marked this conversation as resolved.
_logger.LogMessage($"Found {targetAssemblies.Count} assemblies to evaluate.");

if (!assemblyPath.EndsWith(".dll"))
var resolver = new DefaultAssemblyResolver();
foreach (string referencePath in referencePaths.Select(p => Path.GetDirectoryName(p.ItemSpec)).Distinct())
Comment thread
jviau marked this conversation as resolved.
{
targetAssemblies.Add(assemblyPath);
resolver.AddSearchDirectory(referencePath);
}

ReaderParameters readerParams = new ReaderParameters { AssemblyResolver = resolver };
var functions = new List<SdkFunctionMetadata>();

_logger.LogMessage($"Found {targetAssemblies.Count} assemblies to evaluate in '{sourcePath}':");

foreach (var path in targetAssemblies)
{
using (_logger.Indent())
{
_logger.LogMessage($"{Path.GetFileName(path)}");
_logger.LogMessage($"Collecting function metadata from {Path.GetFileName(path)}.");

using (_logger.Indent())
{
try
{
BaseAssemblyResolver resolver = new DefaultAssemblyResolver();

foreach (string referencePath in referencePaths.Select(p => Path.GetDirectoryName(p)).Distinct())
{
resolver.AddSearchDirectory(referencePath);
}

resolver.AddSearchDirectory(Path.GetDirectoryName(path));

ReaderParameters readerParams = new ReaderParameters { AssemblyResolver = resolver };

var moduleDefinition = ModuleDefinition.ReadModule(path, readerParams);

functions.AddRange(GenerateFunctionMetadata(moduleDefinition));
}
catch (BadImageFormatException)
Expand Down
3 changes: 2 additions & 1 deletion sdk/Sdk/Sdk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

<PropertyGroup>
<MinorProductVersion>17</MinorProductVersion>
<PatchProductVersion>2</PatchProductVersion>
<PatchProductVersion>3</PatchProductVersion>
<VersionSuffix>-preview1</VersionSuffix>
<TargetFrameworks>netstandard2.0;net472</TargetFrameworks>
<PackageId>Microsoft.Azure.Functions.Worker.Sdk</PackageId>
<Description>This package provides development time support for the Azure Functions .NET Worker.</Description>
Expand Down
Loading