-
Notifications
You must be signed in to change notification settings - Fork 201
[MSBUILD SDK] Use custom SDK resolver for integration tests #3220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>netstandard2.0</TargetFramework> | ||
| <LangVersion>latest</LangVersion> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <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="GetSdkFiles" AfterTargets="CoreCompile" Returns="@(_SdkFiles)"> | ||
| <MSBuild Projects="$(AzureFunctionsSdkProject)" Targets="GetSdkFiles"> | ||
| <Output TaskParameter="TargetOutputs" ItemName="_SdkFiles" /> | ||
| </MSBuild> | ||
|
|
||
| <Error Condition="!Exists('$(TargetPath)')" Text="Must build before running 'GetSdkFiles'" /> | ||
|
Check failure on line 24 in test/Azure.Functions.Sdk.Resolver/Azure.Functions.Sdk.Resolver.csproj
|
||
|
|
||
| <ItemGroup> | ||
| <_SdkFiles Include="$(TargetPath)" PackagePath="$(TargetFileName)" /> | ||
| <_SdkFiles Update="@(_SdkFiles)" TargetPath="$(AssemblyName)/%(PackagePath)" /> | ||
| </ItemGroup> | ||
| </Target> | ||
|
|
||
| </Project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # 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, add this target: | ||
|
|
||
| ``` xml | ||
| <PropertyGroup> | ||
| <!-- update this path as needed --> | ||
| <ResolverProject>Azure.Functions.Sdk.Resolver/Azure.Functions.Sdk.Resolver.csproj</ResolverProject> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="$(ResolverProject)" ReferenceOutputAssembly="false" /> | ||
| </ItemGroup> | ||
|
|
||
| <Target Name="_AssignSdkFiles" BeforeTargets="AssignTargetPaths" AfterTargets="ResolveProjectReferences"> | ||
| <MSBuild Projects="$(ResolverProject)" Targets="GetSdkFiles"> | ||
| <Output TaskParameter="TargetOutputs" ItemName="_SdkFiles" /> | ||
| </MSBuild> | ||
|
|
||
| <ItemGroup> | ||
| <None Include="@(_SdkFiles)" TargetPath="resolver/%(_SdkFiles.TargetPath)" CopyToOutputDirectory="PreserveNewest" /> | ||
| </ItemGroup> | ||
| </Target> | ||
| ``` | ||
|
|
||
| The `<some-folder>` from above can then be `<Folder-Containing-Your-Test-Assembly>/resolver` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // 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"); | ||
jviau marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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([]); | ||
| } | ||
| } | ||
| 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"); | ||
jviau marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /// <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(); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.