Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateDependencyFile>false</GenerateDependencyFile>
<CopyBuildOutputToOutputDirectory>false</CopyBuildOutputToOutputDirectory>
<CopyOutputSymbolsToOutputDirectory>false</CopyOutputSymbolsToOutputDirectory>
<CopyBuildOutputToPublishDirectory>false</CopyBuildOutputToPublishDirectory>
<CopyOutputSymbolsToPublishDirectory>false</CopyOutputSymbolsToPublishDirectory>
<AzureFunctionsSdkProject>$(SrcRoot)Azure.Functions.Sdk/Azure.Functions.Sdk.csproj</AzureFunctionsSdkProject>
</PropertyGroup>

Expand All @@ -17,7 +21,24 @@
<PackageReference Include="Microsoft.Build.Framework" Version="17.11.48" ExcludeAssets="runtime" />
</ItemGroup>

<Target Name="_IncludeSdkFiles" AfterTargets="CoreCompile" BeforeTargets="GetCopyToOutputDirectoryItems">
<Target Name="_IncludeSdkFilesForBuild"
AfterTargets="CoreCompile"
BeforeTargets="GetCopyToOutputDirectoryItems"
DependsOnTargets="_CollectSdkFiles">
<ItemGroup>
<AllItemsFullPathWithTargetPath Include="@(_SdkFiles)" CopyToOutputDirectory="PreserveNewest" TargetPath="resolver/%(_SdkFiles.TargetPath)" />
</ItemGroup>
</Target>

<Target Name="_IncludeSdkFilesForPublish"
BeforeTargets="GetCopyToPublishDirectoryItems"
DependsOnTargets="_CollectSdkFiles">
<ItemGroup>
<ContentWithTargetPath Include="@(_SdkFiles)" CopyToPublishDirectory="PreserveNewest" />
</ItemGroup>
</Target>

<Target Name="_CollectSdkFiles" Returns="@(_SdkFiles)">
<MSBuild Projects="$(AzureFunctionsSdkProject)" Targets="GetSdkFiles">
<Output TaskParameter="TargetOutputs" ItemName="_SdkFiles" />
</MSBuild>
Expand All @@ -28,9 +49,15 @@

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

<Target Name="_WriteInitScript" AfterTargets="Publish">
<WriteLinesToFile
File="$(PublishDir)init.ps1"
Lines="$env:MSBUILDADDITIONALSDKRESOLVERSFOLDER = $PSScriptRoot"
Overwrite="true" />
</Target>

</Project>
14 changes: 14 additions & 0 deletions test/Azure.Functions.Sdk.Resolver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ To use this, you must scaffold out the contents as follows:

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

## Ways to use

### 1. From Another Project

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
Expand All @@ -30,3 +34,13 @@ The resolver will be scaffolded out to `$(OutDir)/resolver`. Use the resolver by
string resolverPath = Path.Combine(Path.GetDirectoryName(typeof(SomeTypeInTestAssembly).Assembly.Location)!, "resolver");
Environment.SetEnvironmentVariable("MSBUILDADDITIONALSDKRESOLVERSFOLDER", resolverPath); // Set this before evaluating your project via MSBuild APIs.
```

### 2. Locally

To use this resolver locally (useful for inner dev loop debugging):

1. Publish the project: `dotnet publish -o {path-you-want}`. The output path is optional.
2. Run `init.ps1` from the published location. This will set the env variable for MSBuild to discover the resolver.
1. This sets the env var for the current terminal only.
3. Use `Sdk="Azure.Functions.Sdk/99.99.99"` from a csproj. Must be version `99.99.99`.
4. Restore/build/publish via `dotnet` in the same environment init.ps1 was ran.