Skip to content

Commit 4637043

Browse files
authored
Add option to disable CopyFilesMarkedCopyLocal target (#395)
This adds a new property `SkipCopyFilesMarkedCopyLocal` which can be set to `true` to disable the `CopyFilesMarkedCopyLocal` target. ```xml <PropertyGroup> <SkipCopyFilesMarkedCopyLocal>true</SkipCopyFilesMarkedCopyLocal> </PropertyGroup> ```
1 parent 0180145 commit 4637043

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

src/NoTargets.UnitTests/Microsoft.Build.NoTargets.UnitTests.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
<ProjectReference Include="..\NoTargets\Microsoft.Build.NoTargets.csproj" ReferenceOutputAssembly="false" />
1616
</ItemGroup>
1717
<ItemGroup>
18-
<None Include="..\NoTargets\Sdk\Sdk.props" Link="Sdk\Sdk.props" CopyToOutputDirectory="PreserveNewest" />
19-
<None Include="..\NoTargets\Sdk\Sdk.targets" Link="Sdk\Sdk.targets" CopyToOutputDirectory="PreserveNewest" />
18+
<None Include="..\NoTargets\Sdk\**\*" Link="Sdk\%(RecursiveDir)%(Filename)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
2019
</ItemGroup>
2120
</Project>

src/NoTargets.UnitTests/NoTargetsTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,25 @@
1313
using System.Collections.Generic;
1414
using System.IO;
1515
using System.Linq;
16+
using System.Reflection;
1617
using Xunit;
1718

1819
namespace Microsoft.Build.NoTargets.UnitTests
1920
{
2021
public class NoTargetsTests : MSBuildSdkTestBase
2122
{
23+
[Fact]
24+
public void CanDisableCopyFilesMarkedCopyLocal()
25+
{
26+
ProjectCreator.Templates.NoTargetsProject(
27+
path: GetTempFileWithExtension(".csproj"))
28+
.Property("SkipCopyFilesMarkedCopyLocal", bool.TrueString)
29+
.ItemInclude("ReferenceCopyLocalPaths", Assembly.GetExecutingAssembly().Location)
30+
.TryBuild("_CopyFilesMarkedCopyLocal", out bool result, out BuildOutput buildOutput);
31+
32+
result.ShouldBeTrue(buildOutput.GetConsoleLog());
33+
}
34+
2235
[Theory]
2336
[InlineData("BeforeCompile")]
2437
[InlineData("AfterCompile")]
@@ -181,6 +194,9 @@ public void ProjectsCanDependOnNoTargetsProjects()
181194
[InlineData("ProduceReferenceAssembly", null, "false")]
182195
[InlineData("SkipCopyBuildProduct", "false", "false")]
183196
[InlineData("SkipCopyBuildProduct", null, "true")]
197+
[InlineData("SkipCopyFilesMarkedCopyLocal", "false", "false")]
198+
[InlineData("SkipCopyFilesMarkedCopyLocal", "true", "true")]
199+
[InlineData("SkipCopyFilesMarkedCopyLocal", null, "")]
184200
public void PropertiesHaveExpectedValues(string propertyName, string value, string expectedValue)
185201
{
186202
ProjectCreator.Templates.NoTargetsProject(
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<Project>
2+
<!-- Disables the _CopyFilesMarkedCopyLocal target by overriding it -->
3+
<Target Name="_CopyFilesMarkedCopyLocal" />
4+
</Project>

src/NoTargets/Sdk/Sdk.targets

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,7 @@
101101

102102
<Target Name="_GenerateCompileInputs" />
103103
<Target Name="_GenerateCompileDependencyCache" />
104+
105+
<!-- Disables the _CopyFilesMarkedCopyLocal target to not copy references when SkipCopyFilesMarkedCopyLocal is set to false. -->
106+
<Import Project="DisableCopyFilesMarkedCopyLocal.targets" Condition="'$(SkipCopyFilesMarkedCopyLocal)' == 'true'" />
104107
</Project>

0 commit comments

Comments
 (0)