Skip to content
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

Added support for skipping bicep build in MSBuild targets #11916

Merged
merged 3 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions src/Bicep.MSBuild.E2eTests/examples/csharp/csharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

<ItemGroup>
<Bicep Include="empty.bicep"/>
<Bicep Include="empty2.bicep"/>
<Bicep Include="skip.bicep" NoBuild="true" />
<Bicep Include="skip2.bicep" NoBuild="true" />
</ItemGroup>
</Project>

Empty file.
Empty file.
Empty file.
1 change: 1 addition & 0 deletions src/Bicep.MSBuild.E2eTests/examples/simple/simple.proj
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@

<ItemGroup>
<Bicep Include="empty.bicep"/>
<Bicep Include="skip.bicep" NoBuild="true" />
</ItemGroup>
</Project>
Empty file.
16 changes: 16 additions & 0 deletions src/Bicep.MSBuild.E2eTests/src/csharp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,21 @@ describe("msbuild", () => {
const templateRelativePath = "bin/Debug/net7.0/empty.json";
example.expectTemplate(templateRelativePath);

const templateRelativePath2 = "bin/Debug/net7.0/empty2.json";
example.expectTemplate(templateRelativePath2);

const skipFileRelativePath = "bin/Debug/net7.0/skip.json";
example.expectNoFile(skipFileRelativePath);

const skipFileRelativePath2 = "bin/Debug/net7.0/skip2.json";
example.expectNoFile(skipFileRelativePath2);

const cleanResult = example.clean();
expect(cleanResult.stderr).toBe("");
example.expectNoFile(templateRelativePath);
example.expectNoFile(templateRelativePath2);
example.expectNoFile(skipFileRelativePath);
example.expectNoFile(skipFileRelativePath2);

example.cleanProjectDir();

Expand All @@ -26,6 +38,10 @@ describe("msbuild", () => {

// both build and publish outputs should be present
example.expectTemplate(templateRelativePath);
example.expectTemplate(templateRelativePath2);
example.expectTemplate("bin/Debug/net7.0/publish/empty.json");
example.expectTemplate("bin/Debug/net7.0/publish/empty2.json");
example.expectNoFile("bin/Debug/net7.0/publish/skip.json");
example.expectNoFile("bin/Debug/net7.0/publish/skip2.json");
});
});
6 changes: 6 additions & 0 deletions src/Bicep.MSBuild.E2eTests/src/simple.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ describe("msbuild", () => {
expect(buildResult.stderr).toBe("");
const templateRelativePath = "bin/Debug/net472/empty.json";
example.expectTemplate(templateRelativePath);
const skippedFileRelativePath = "bin/Debug/net472/skip.json";
example.expectNoFile(skippedFileRelativePath);

const cleanResult = example.clean();
expect(cleanResult.stderr).toBe("");
Expand All @@ -25,5 +27,9 @@ describe("msbuild", () => {
// both build and publish outputs should be present
example.expectTemplate(templateRelativePath);
example.expectTemplate("bin/Debug/net472/publish/empty.json");

// skipped file must not be present in either build or publish output directory
example.expectNoFile(skippedFileRelativePath);
example.expectNoFile("bin/Debug/net472/publish/skip.json");
});
});
9 changes: 7 additions & 2 deletions src/Bicep.MSBuild/build/Azure.Bicep.MSBuild.targets
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

<Target Name="BeforeBicepCompile" Condition=" @(Bicep) != '' " BeforeTargets="BicepCompile">
<ItemGroup>
<_BicepResolvedIntermediate Include="@(Bicep)">
<!-- consider only files without NoBuild metadata set -->
<_BicepResolvedIntermediate Include="@(Bicep)" Condition=" %(Bicep.NoBuild) != 'true' ">
<!-- populate missing output file metadata using the default path -->
<OutputFile Condition=" %(Bicep.OutputFile) == '' ">$(BicepOutputPath)\%(FileName)$(BicepDefaultOutputFileExtension)</OutputFile>
</_BicepResolvedIntermediate>
Expand All @@ -18,13 +19,17 @@
</_BicepResolved>

<_BicepOutputFile Include="%(_BicepResolved.OutputFile)" />

<!-- collect all the files with NoBuild metadata set -->
<_BicepSkipped Include="@(Bicep)" Condition=" %(Bicep.NoBuild) == 'true' " />
</ItemGroup>

<!-- pre-create directories for all the outputs in case they don't exist -->
<MakeDir Directories=" %(_BicepOutputFile.RootDir)%(Directory)" />
<Error Text="The path to the Bicep compiler is not set. Reference the appropriate Azure.Bicep.CommandLine.* package for your runtime or set the BicepPath property." Condition=" $(BicepPath) == '' " />
</Target>

<Target Name="BicepCompile" Inputs="@(_BicepResolved)" Outputs="%(_BicepResolved.OutputFile)" DependsOnTargets="$(BicepCompileDependsOn)" AfterTargets="$(BicepCompileAfterTargets)" BeforeTargets="$(BicepCompileBeforeTargets)">
<Target Name="BicepCompile" Inputs="@(_BicepResolved);@(_BicepSkipped)" Outputs="%(_BicepResolved.OutputFile)" DependsOnTargets="$(BicepCompileDependsOn)" AfterTargets="$(BicepCompileAfterTargets)" BeforeTargets="$(BicepCompileBeforeTargets)">
<Bicep SourceFile="%(_BicepResolved.FullPath)" OutputFile="%(OutputFile)" ToolExe="$(BicepPath)" YieldDuringToolExecution="true" />
<Message Importance="High" Text="$(MSBuildProjectName) -&gt; %(_BicepResolved.OutputFile)" />

Expand Down
Loading