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 @@ -70,6 +70,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Functions.Sdk", "src\
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Functions.Sdk.Tests", "test\Azure.Functions.Sdk.Tests\Azure.Functions.Sdk.Tests.csproj", "{CB71124E-019E-4A81-882B-D96DCF574C37}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Functions.Sdk.Resolver", "test\Azure.Functions.Sdk.Resolver\Azure.Functions.Sdk.Resolver.csproj", "{BC2EF124-0868-4FCC-A711-DB4C1C860CB8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -160,6 +162,10 @@ Global
{CB71124E-019E-4A81-882B-D96DCF574C37}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CB71124E-019E-4A81-882B-D96DCF574C37}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CB71124E-019E-4A81-882B-D96DCF574C37}.Release|Any CPU.Build.0 = Release|Any CPU
{BC2EF124-0868-4FCC-A711-DB4C1C860CB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BC2EF124-0868-4FCC-A711-DB4C1C860CB8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BC2EF124-0868-4FCC-A711-DB4C1C860CB8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BC2EF124-0868-4FCC-A711-DB4C1C860CB8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -188,6 +194,7 @@ Global
{750993F6-4E3B-411B-9471-74CEA4F9C23A} = {E785547C-7546-469F-827C-FDF999D5D7E8}
{02CBCC67-A10C-4064-AA5D-84533AC02342} = {083592CA-7DAB-44CE-8979-44FAFA46AEC3}
{CB71124E-019E-4A81-882B-D96DCF574C37} = {FD7243E4-BF18-43F8-8744-BA1D17ACF378}
{BC2EF124-0868-4FCC-A711-DB4C1C860CB8} = {FD7243E4-BF18-43F8-8744-BA1D17ACF378}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {497D2ED4-A13E-4BCA-8D29-F30CA7D0EA4A}
Expand Down
12 changes: 9 additions & 3 deletions src/Azure.Functions.Sdk/Azure.Functions.Sdk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
<None Update="@(None)"
PackagePath="%(None.PackagePath)$([System.String]::new('%(RecursiveDir)').Substring(0, 1).ToLowerInvariant())$([System.String]::new('%(RecursiveDir)').Substring(1))%(Filename)%(Extension)"
Condition="'%(None.CamelCasePath)' == 'true' AND '%(RecursiveDir)' != ''" />
<None Update="@(None)"
PackagePath="%(None.PackagePath)%(Filename)%(Extension)"
Condition="'%(None.CamelCasePath)' == 'true' AND '%(RecursiveDir)' == ''" />
</ItemGroup>
</Target>

Expand All @@ -54,13 +57,16 @@
</ItemGroup>
</Target>

<!-- Test project calls this to get all SDK files. -->
<Target Name="GetSdkFiles" DependsOnTargets="_AddPackagePath" Returns="@(_SdkFiles)">
<!-- Test project calls this to scaffold out this SDK in its expected structure. -->
<Target Name="GetSdkFiles"
DependsOnTargets="_AddPackagePath;IncludeReferenceCopyLocalPathsInBuildOutputInPackage;_GetBuildOutputFilesWithTfm"
Returns="@(_SdkFiles)">
<ItemGroup>
<_SdkFilesTemp Include="@(None->WithMetadataValue('SdkFile', 'true'))" />
<_SdkFilesTemp Include="@(BuildOutputInPackage)" PackagePath="tools/netstandard2.0/%(BuildOutputInPackage.TargetPath)" />
</ItemGroup>

<ConvertToAbsolutePath Paths="@(_SdkFilesTemp)">
<ConvertToAbsolutePath Paths="@(_SdkFilesTemp->Distinct())">
<Output TaskParameter="AbsolutePaths" ItemName="_SdkFiles" />
</ConvertToAbsolutePath>
</Target>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<CopyBuildOutputToOutputDirectory>false</CopyBuildOutputToOutputDirectory>
<AzureFunctionsSdkProject>$(SrcRoot)Azure.Functions.Sdk/Azure.Functions.Sdk.csproj</AzureFunctionsSdkProject>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="$(AzureFunctionsSdkProject)" ReferenceOutputAssembly="false" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Build.Framework" Version="17.11.48" ExcludeAssets="runtime" />
</ItemGroup>

<Target Name="_IncludeSdkFiles" AfterTargets="CoreCompile" BeforeTargets="GetCopyToOutputDirectoryItems">
<MSBuild Projects="$(AzureFunctionsSdkProject)" Targets="GetSdkFiles">
<Output TaskParameter="TargetOutputs" ItemName="_SdkFiles" />
</MSBuild>

<ConvertToAbsolutePath Paths="@(IntermediateAssembly)">
<Output TaskParameter="AbsolutePaths" ItemName="_ResolverAssemblyFullPath" />
</ConvertToAbsolutePath>

<ItemGroup>
<_SdkFiles Include="@(_ResolverAssemblyFullPath)" PackagePath="%(Filename)%(Extension)" />
<_SdkFiles Update="@(_SdkFiles)" TargetPath="resolver/$(AssemblyName)/%(PackagePath)" />
<AllItemsFullPathWithTargetPath Include="@(_SdkFiles)" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Target>

</Project>
32 changes: 32 additions & 0 deletions test/Azure.Functions.Sdk.Resolver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Azure.Functions.Sdk.Resolver

This project scaffolds out a custom `Microsoft.Build.Framework.SdkResolver` which will automatically resolve the `Azure.Functions.Sdk/99.99.99` SDK for integration testing.

To use this, you must scaffold out the contents as follows:

```
- <some-folder>
|- Azure.Functions.Sdk.Resolver
|- Azure.Functions.Sdk.Resolver.dll
|- sdk/*
|- targets/*
|- build/*
|- tools/*
```

You then set the environment variable `MSBUILDADDITIONALSDKRESOLVERSFOLDER=<some-folder>`.

To use from another project, like a test project, simply reference the project. Consider adding `ReferenceOutputAssembly="false"` as the dll is not directly needed.

``` xml
<ItemGroup>
<ProjectReference Include="Azure.Functions.Sdk.Resolver/Azure.Functions.Sdk.Resolver.csproj" ReferenceOutputAssembly="false" />
</ItemGroup>
```

The resolver will be scaffolded out to `$(OutDir)/resolver`. Use the resolver by setting the appropriate environment variable:

``` csharp
string resolverPath = Path.Combine(Path.GetDirectoryName(typeof(SomeTypeInTestAssembly).Assembly.Location)!, "resolver");
Environment.SetEnvironmentVariable("MSBUILDADDITIONALSDKRESOLVERSFOLDER", resolverPath); // Set this before evaluating your project via MSBuild APIs.
```
26 changes: 26 additions & 0 deletions test/Azure.Functions.Sdk.Resolver/TestSdkResolver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using Microsoft.Build.Framework;

namespace Azure.Functions.Sdk.Resolver;

public class TestSdkResolver : SdkResolver
{
private static readonly string SdkPath = Path.Combine(
Path.GetDirectoryName(typeof(TestSdkResolver).Assembly.Location), "sdk");

public override string Name => "Test Azure Functions SDK Resolver";

public override int Priority => 1000;

public override SdkResult Resolve(SdkReference sdkReference, SdkResolverContext context, SdkResultFactory factory)
{
if (sdkReference.Name == "Azure.Functions.Sdk")
{
return factory.IndicateSuccess(SdkPath, "99.99.99"); // test version.
}

return factory.IndicateFailure([]);
}
}
17 changes: 5 additions & 12 deletions test/Azure.Functions.Sdk.Tests/Azure.Functions.Sdk.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AzureFunctionsSdkProject>$(SrcRoot)Azure.Functions.Sdk/Azure.Functions.Sdk.csproj</AzureFunctionsSdkProject>
<ResolverProject>../Azure.Functions.Sdk.Resolver/Azure.Functions.Sdk.Resolver.csproj</ResolverProject>
</PropertyGroup>

<ItemGroup>
<Using Include="AwesomeAssertions" />
<Using Include="Moq" />
<Using Include="Xunit" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(AzureFunctionsSdkProject)" />
<ProjectReference Include="$(SrcRoot)Azure.Functions.Sdk/Azure.Functions.Sdk.csproj" />
<ProjectReference Include="$(ResolverProject)" ReferenceOutputAssembly="false" />
</ItemGroup>

<ItemGroup>
Expand All @@ -40,14 +43,4 @@
<PackageReference Include="Microsoft.CodeAnalysis.ResxSourceGenerator" Version="5.0.0-1.25277.114" PrivateAssets="all" />
</ItemGroup>

<Target Name="_CopySdkFiles" BeforeTargets="AssignTargetPaths">
<MSBuild Projects="$(AzureFunctionsSdkProject)" Targets="GetSdkFiles">
<Output TaskParameter="TargetOutputs" ItemName="_SdkFiles" />
</MSBuild>

<ItemGroup>
<None Include="@(_SdkFiles)" TargetPath="sdk/%(_SdkFiles.PackagePath)%(Filename)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Target>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,12 @@ namespace Azure.Functions.Sdk.Tests.Integration;

internal static class MSBuildExtensions
{
private static readonly string ThisAssemblyDirectory =
Path.GetDirectoryName(typeof(MSBuildExtensions).Assembly.Location)!;

private static readonly ImmutableDictionary<string, string> DefaultGlobalProperties =
ImmutableDictionary.CreateRange(
[
KeyValuePair.Create("ImportDirectoryBuildProps", bool.FalseString),
KeyValuePair.Create("ImportDirectoryPackagesProps", bool.FalseString),
KeyValuePair.Create("ImportDirectoryBuildTargets", bool.FalseString),
KeyValuePair.Create("AzureFunctionsSdkTasksAssembly", Path.Combine(ThisAssemblyDirectory, "Azure.Functions.Sdk.dll")),
KeyValuePair.Create("RestoreSources", "https://api.nuget.org/v3/index.json" )
]);

Expand All @@ -35,12 +31,11 @@ public static ProjectCreator AzureFunctionsProject(
return ProjectCreator.Create(
path: path,
projectCollection: projectCollection,
sdk: "Azure.Functions.Sdk/99.99.99",
globalProperties: GetGlobalProperties(globalProperties))
.Import(Path.Combine(ThisAssemblyDirectory, "sdk", "sdk", "Sdk.props"))
.PropertyGroup()
.Property("TargetFramework", targetFramework)
.CustomAction(configure)
.Import(Path.Combine(ThisAssemblyDirectory, "sdk", "sdk", "Sdk.targets"));
.CustomAction(configure);
}

public static ProjectCreator WriteSourceFile(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using AwesomeAssertions;
using Microsoft.Build.Utilities.ProjectCreation;

namespace Azure.Functions.Sdk.Tests.Integration;
Expand Down
1 change: 0 additions & 1 deletion test/Azure.Functions.Sdk.Tests/LogMessageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Collections;
using System.Globalization;
using System.Resources;
using AwesomeAssertions;
using NuGet.Common;

namespace Azure.Functions.Sdk.Tests;
Expand Down
17 changes: 5 additions & 12 deletions test/Azure.Functions.Sdk.Tests/ModuleInitializer.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.



using System.Runtime.CompilerServices;
using AwesomeAssertions;
using Microsoft.Build.Utilities.ProjectCreation;

namespace Azure.Functions.Sdk.Tests;

internal static class ModuleInitializer
{
private static readonly string ResolverPath = Path.Combine(
Path.GetDirectoryName(typeof(ModuleInitializer).Assembly.Location)!, "resolver");

/// <summary>
/// We cannot include MSBuild assemblies in our output, because they will interfere with
/// MSBuilds assembly scanning. Instead we use the MSBuildLocator to resolve them at runtime.
/// </summary>
[ModuleInitializer]
internal static void InitializeMSBuild()
internal static void Initialize()
{
Environment.SetEnvironmentVariable("MSBUILDADDITIONALSDKRESOLVERSFOLDER", ResolverPath);
MSBuildAssemblyResolver.Register();
}

/// <summary>
/// Bootstrap our custom formatters for AwesomeAssertions at startup.
/// </summary>
[ModuleInitializer]
internal static void InitializeFormatters()
{
FormatterResolver.Initialize();
}
}