Skip to content

Commit f54e104

Browse files
jviauCopilot
andauthored
[MSBUILD SDK] Support publish for Resolver.csproj (#3223)
* Support publish for Resolver.csproj * Add init.ps1 script * Update test/Azure.Functions.Sdk.Resolver/README.md Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent f2e03be commit f54e104

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

test/Azure.Functions.Sdk.Resolver/Azure.Functions.Sdk.Resolver.csproj

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
<LangVersion>latest</LangVersion>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
8+
<GenerateDependencyFile>false</GenerateDependencyFile>
89
<CopyBuildOutputToOutputDirectory>false</CopyBuildOutputToOutputDirectory>
10+
<CopyOutputSymbolsToOutputDirectory>false</CopyOutputSymbolsToOutputDirectory>
11+
<CopyBuildOutputToPublishDirectory>false</CopyBuildOutputToPublishDirectory>
12+
<CopyOutputSymbolsToPublishDirectory>false</CopyOutputSymbolsToPublishDirectory>
913
<AzureFunctionsSdkProject>$(SrcRoot)Azure.Functions.Sdk/Azure.Functions.Sdk.csproj</AzureFunctionsSdkProject>
1014
</PropertyGroup>
1115

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

20-
<Target Name="_IncludeSdkFiles" AfterTargets="CoreCompile" BeforeTargets="GetCopyToOutputDirectoryItems">
24+
<Target Name="_IncludeSdkFilesForBuild"
25+
AfterTargets="CoreCompile"
26+
BeforeTargets="GetCopyToOutputDirectoryItems"
27+
DependsOnTargets="_CollectSdkFiles">
28+
<ItemGroup>
29+
<AllItemsFullPathWithTargetPath Include="@(_SdkFiles)" CopyToOutputDirectory="PreserveNewest" TargetPath="resolver/%(_SdkFiles.TargetPath)" />
30+
</ItemGroup>
31+
</Target>
32+
33+
<Target Name="_IncludeSdkFilesForPublish"
34+
BeforeTargets="GetCopyToPublishDirectoryItems"
35+
DependsOnTargets="_CollectSdkFiles">
36+
<ItemGroup>
37+
<ContentWithTargetPath Include="@(_SdkFiles)" CopyToPublishDirectory="PreserveNewest" />
38+
</ItemGroup>
39+
</Target>
40+
41+
<Target Name="_CollectSdkFiles" Returns="@(_SdkFiles)">
2142
<MSBuild Projects="$(AzureFunctionsSdkProject)" Targets="GetSdkFiles">
2243
<Output TaskParameter="TargetOutputs" ItemName="_SdkFiles" />
2344
</MSBuild>
@@ -28,9 +49,15 @@
2849

2950
<ItemGroup>
3051
<_SdkFiles Include="@(_ResolverAssemblyFullPath)" PackagePath="%(Filename)%(Extension)" />
31-
<_SdkFiles Update="@(_SdkFiles)" TargetPath="resolver/$(AssemblyName)/%(PackagePath)" />
32-
<AllItemsFullPathWithTargetPath Include="@(_SdkFiles)" CopyToOutputDirectory="PreserveNewest" />
52+
<_SdkFiles Update="@(_SdkFiles)" TargetPath="$(AssemblyName)/%(PackagePath)" />
3353
</ItemGroup>
3454
</Target>
3555

56+
<Target Name="_WriteInitScript" AfterTargets="Publish">
57+
<WriteLinesToFile
58+
File="$(PublishDir)init.ps1"
59+
Lines="$env:MSBUILDADDITIONALSDKRESOLVERSFOLDER = $PSScriptRoot"
60+
Overwrite="true" />
61+
</Target>
62+
3663
</Project>

test/Azure.Functions.Sdk.Resolver/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ To use this, you must scaffold out the contents as follows:
1616

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

19+
## Ways to use
20+
21+
### 1. From Another Project
22+
1923
To use from another project, like a test project, simply reference the project. Consider adding `ReferenceOutputAssembly="false"` as the dll is not directly needed.
2024

2125
``` xml
@@ -30,3 +34,13 @@ The resolver will be scaffolded out to `$(OutDir)/resolver`. Use the resolver by
3034
string resolverPath = Path.Combine(Path.GetDirectoryName(typeof(SomeTypeInTestAssembly).Assembly.Location)!, "resolver");
3135
Environment.SetEnvironmentVariable("MSBUILDADDITIONALSDKRESOLVERSFOLDER", resolverPath); // Set this before evaluating your project via MSBuild APIs.
3236
```
37+
38+
### 2. Locally
39+
40+
To use this resolver locally (useful for inner dev loop debugging):
41+
42+
1. Publish the project: `dotnet publish -o {path-you-want}`. The output path is optional.
43+
2. Run `init.ps1` from the published location. This will set the env variable for MSBuild to discover the resolver.
44+
1. This sets the env var for the current terminal only.
45+
3. Use `Sdk="Azure.Functions.Sdk/99.99.99"` from a csproj. Must be version `99.99.99`.
46+
4. Restore/build/publish via `dotnet` in the same environment init.ps1 was run.

0 commit comments

Comments
 (0)