-
Notifications
You must be signed in to change notification settings - Fork 203
[MSBUILD SDK] Add dotnet clean support #3372
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 all commits
Commits
Show all changes
2 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
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
85 changes: 85 additions & 0 deletions
85
test/Azure.Functions.Sdk.Tests/Integration/SdkEndToEndTests.Clean.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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| // 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.Utilities.ProjectCreation; | ||
|
|
||
| namespace Azure.Functions.Sdk.Tests.Integration; | ||
|
|
||
| public partial class SdkEndToEndTests | ||
| { | ||
| [Fact] | ||
| public void Clean_RemovesFunctionsArtifacts() | ||
| { | ||
| // Arrange | ||
| ProjectCreator project = ProjectCreator.Templates.AzureFunctionsProject( | ||
| GetTempCsproj()) | ||
| .Property("AssemblyName", "MyFunctionApp") | ||
| .WriteSourceFile("Program.cs", Resources.Program_Minimal_cs); | ||
|
|
||
| project.Build(restore: true).Should().BeSuccessful().And.HaveNoIssues(); | ||
|
|
||
| string outputPath = project.GetOutputPath(); | ||
| string intermediatePath = project.GetIntermediateOutputPath(); | ||
| string extensionProjectDir = project.GetFunctionsExtensionProjectDirectory(); | ||
|
|
||
| // Verify artifacts exist after build. | ||
| File.Exists(Path.Combine(outputPath, "worker.config.json")).Should().BeTrue("worker.config.json should exist in output after build"); | ||
| File.Exists(Path.Combine(outputPath, "extensions.json")).Should().BeTrue("extensions.json should exist in output after build"); | ||
| Directory.Exists(Path.Combine(outputPath, Constants.ExtensionsOutputFolder)).Should().BeTrue(".azurefunctions should exist in output after build"); | ||
| File.Exists(Path.Combine(intermediatePath, "worker.config.json")).Should().BeTrue("worker.config.json should exist in intermediate after build"); | ||
| File.Exists(Path.Combine(intermediatePath, "extensions.json")).Should().BeTrue("extensions.json should exist in intermediate after build"); | ||
| File.Exists(Path.Combine(intermediatePath, "extensions.json.hash")).Should().BeTrue("extensions.json.hash should exist in intermediate after build"); | ||
| Directory.Exists(extensionProjectDir).Should().BeTrue("extension project directory should exist after build"); | ||
|
|
||
| // Act | ||
| BuildOutput cleanOutput = project.Clean(); | ||
|
|
||
| // Assert | ||
| cleanOutput.Should().BeSuccessful(); | ||
| File.Exists(Path.Combine(intermediatePath, "worker.config.json")).Should().BeFalse("worker.config.json should be cleaned from intermediate"); | ||
| File.Exists(Path.Combine(intermediatePath, "extensions.json")).Should().BeFalse("extensions.json should be cleaned from intermediate"); | ||
| File.Exists(Path.Combine(intermediatePath, "extensions.json.hash")).Should().BeFalse("extensions.json.hash should be cleaned from intermediate"); | ||
| Directory.Exists(extensionProjectDir).Should().BeFalse("extension project directory should be cleaned"); | ||
| Directory.Exists(Path.Combine(outputPath, Constants.ExtensionsOutputFolder)).Should().BeFalse(".azurefunctions should be cleaned from output"); | ||
| } | ||
|
jviau marked this conversation as resolved.
|
||
|
|
||
| [Fact] | ||
| public void Clean_MultiTarget_RemovesFunctionsArtifacts() | ||
| { | ||
| // Arrange | ||
| string[] targetFrameworks = ["net8.0", "net481"]; | ||
| ProjectCreator project = ProjectCreator.Templates.AzureFunctionsProject( | ||
| GetTempCsproj(), targetFramework: null) | ||
| .TargetFrameworks(targetFrameworks) | ||
| .Property("AssemblyName", "MyFunctionApp") | ||
| .Property("LangVersion", "latest") | ||
| .WriteSourceFile("Program.cs", Resources.Program_Minimal_cs); | ||
|
|
||
| project.Build(restore: true).Should().BeSuccessful().And.HaveNoIssues(); | ||
|
|
||
| // Verify artifacts exist for each TFM after build. | ||
| foreach (string tfm in targetFrameworks) | ||
| { | ||
| string outputPath = GetMultiTargetOutputPath(project, tfm); | ||
| string extensionProjectDir = project.GetFunctionsExtensionProjectDirectory(tfm); | ||
|
|
||
| File.Exists(Path.Combine(outputPath, "worker.config.json")).Should().BeTrue($"worker.config.json should exist in {tfm} output after build"); | ||
| Directory.Exists(Path.Combine(outputPath, Constants.ExtensionsOutputFolder)).Should().BeTrue($".azurefunctions should exist in {tfm} output after build"); | ||
| Directory.Exists(extensionProjectDir).Should().BeTrue($"extension project directory should exist for {tfm} after build"); | ||
| } | ||
|
|
||
| // Act | ||
| BuildOutput cleanOutput = project.Clean(); | ||
|
|
||
| // Assert | ||
| cleanOutput.Should().BeSuccessful(); | ||
| foreach (string tfm in targetFrameworks) | ||
| { | ||
| string outputPath = GetMultiTargetOutputPath(project, tfm); | ||
| string extensionProjectDir = project.GetFunctionsExtensionProjectDirectory(tfm); | ||
|
|
||
| Directory.Exists(extensionProjectDir).Should().BeFalse($"extension project directory should be cleaned for {tfm}"); | ||
| Directory.Exists(Path.Combine(outputPath, Constants.ExtensionsOutputFolder)).Should().BeFalse($".azurefunctions should be cleaned from {tfm} output"); | ||
| } | ||
|
jviau marked this conversation as 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
Oops, something went wrong.
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.