Skip to content

Commit

Permalink
Add option to disable CopyFilesMarkedCopyLocal target (#395)
Browse files Browse the repository at this point in the history
This adds a new property `SkipCopyFilesMarkedCopyLocal` which can be set to `true` to disable the `CopyFilesMarkedCopyLocal` target.

```xml
<PropertyGroup>
  <SkipCopyFilesMarkedCopyLocal>true</SkipCopyFilesMarkedCopyLocal>
</PropertyGroup>
```
  • Loading branch information
ViktorHofer authored Nov 7, 2022
1 parent 0180145 commit 4637043
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<ProjectReference Include="..\NoTargets\Microsoft.Build.NoTargets.csproj" ReferenceOutputAssembly="false" />
</ItemGroup>
<ItemGroup>
<None Include="..\NoTargets\Sdk\Sdk.props" Link="Sdk\Sdk.props" CopyToOutputDirectory="PreserveNewest" />
<None Include="..\NoTargets\Sdk\Sdk.targets" Link="Sdk\Sdk.targets" CopyToOutputDirectory="PreserveNewest" />
<None Include="..\NoTargets\Sdk\**\*" Link="Sdk\%(RecursiveDir)%(Filename)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Project>
16 changes: 16 additions & 0 deletions src/NoTargets.UnitTests/NoTargetsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,25 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Xunit;

namespace Microsoft.Build.NoTargets.UnitTests
{
public class NoTargetsTests : MSBuildSdkTestBase
{
[Fact]
public void CanDisableCopyFilesMarkedCopyLocal()
{
ProjectCreator.Templates.NoTargetsProject(
path: GetTempFileWithExtension(".csproj"))
.Property("SkipCopyFilesMarkedCopyLocal", bool.TrueString)
.ItemInclude("ReferenceCopyLocalPaths", Assembly.GetExecutingAssembly().Location)
.TryBuild("_CopyFilesMarkedCopyLocal", out bool result, out BuildOutput buildOutput);

result.ShouldBeTrue(buildOutput.GetConsoleLog());
}

[Theory]
[InlineData("BeforeCompile")]
[InlineData("AfterCompile")]
Expand Down Expand Up @@ -181,6 +194,9 @@ public void ProjectsCanDependOnNoTargetsProjects()
[InlineData("ProduceReferenceAssembly", null, "false")]
[InlineData("SkipCopyBuildProduct", "false", "false")]
[InlineData("SkipCopyBuildProduct", null, "true")]
[InlineData("SkipCopyFilesMarkedCopyLocal", "false", "false")]
[InlineData("SkipCopyFilesMarkedCopyLocal", "true", "true")]
[InlineData("SkipCopyFilesMarkedCopyLocal", null, "")]
public void PropertiesHaveExpectedValues(string propertyName, string value, string expectedValue)
{
ProjectCreator.Templates.NoTargetsProject(
Expand Down
4 changes: 4 additions & 0 deletions src/NoTargets/Sdk/DisableCopyFilesMarkedCopyLocal.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<Project>
<!-- Disables the _CopyFilesMarkedCopyLocal target by overriding it -->
<Target Name="_CopyFilesMarkedCopyLocal" />
</Project>
3 changes: 3 additions & 0 deletions src/NoTargets/Sdk/Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,7 @@

<Target Name="_GenerateCompileInputs" />
<Target Name="_GenerateCompileDependencyCache" />

<!-- Disables the _CopyFilesMarkedCopyLocal target to not copy references when SkipCopyFilesMarkedCopyLocal is set to false. -->
<Import Project="DisableCopyFilesMarkedCopyLocal.targets" Condition="'$(SkipCopyFilesMarkedCopyLocal)' == 'true'" />
</Project>

0 comments on commit 4637043

Please sign in to comment.