-
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
test/Azure.Functions.Sdk.Resolver/Azure.Functions.Sdk.Resolver.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 resolve by setting the appropriate environment variable: | ||
|
|
||
| ``` csharp | ||
| string resolverPath = Path.Combine(Path.GetDirectoryName(typeof(SomeTypeInTestAssembly).Assembly.Location)!, "resolver"); | ||
| Environment.SetEnvironmentVariable("MSBUILDADDITIONALSDKRESOLVERSFOLDER", resolverPath); | ||
| ``` | ||
jviau marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"); | ||
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([]); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
test/Azure.Functions.Sdk.Tests/Integration/SdkEndToEndTests.Restore.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.