Skip to content

Commit 64f65f0

Browse files
authored
Add DeployToNanoDevice project property to control deployment (#892)
1 parent 0aaa018 commit 64f65f0

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

vs-extension.shared/Utilities/ReferenceCrawler.cs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
//
2-
// Copyright (c) .NET Foundation and Contributors
3-
// See LICENSE file in the project root for full license information.
4-
//
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
53

6-
using Microsoft.VisualStudio.ProjectSystem;
7-
using Microsoft.VisualStudio.ProjectSystem.References;
84
using System;
95
using System.Collections.Generic;
106
using System.Linq;
117
using System.Reflection;
128
using System.Threading.Tasks;
9+
using Microsoft.VisualStudio.ProjectSystem;
10+
using Microsoft.VisualStudio.ProjectSystem.References;
1311

1412
namespace nanoFramework.Tools.VisualStudio.Extension
1513
{
@@ -90,9 +88,12 @@ public static async Task CollectAssembliesToDeployAsync(
9088
foreach (IAssemblyReference assemblyReference in
9189
await project.Services.AssemblyReferences.GetResolvedReferencesAsync())
9290
{
93-
// As assemblyPathsToDeploy is a HashSet, the same path will not occure more than once even if added
94-
// more than once by distinct projects referencing the same NuGet package for example.
95-
assemblyPathsToDeploy.Add(await assemblyReference.GetFullPathAsync());
91+
if (await ShouldDeployToNanoDeviceAsync(assemblyReference))
92+
{
93+
// As assemblyPathsToDeploy is a HashSet, the same path will not occure more than once even if added
94+
// more than once by distinct projects referencing the same NuGet package for example.
95+
assemblyPathsToDeploy.Add(await assemblyReference.GetFullPathAsync());
96+
}
9697
}
9798

9899
// Recursively process referenced projects in the solution:
@@ -125,6 +126,17 @@ await CollectAssembliesToDeployAsync(
125126
}
126127
}
127128

129+
/// <summary>
130+
/// Find out if a referenced assembly should be included in the deployment or not.
131+
/// If the Reference element in the (imported) project file has the property "DeployToNanoDevice" set to false,
132+
/// it will not be included. If the property is not present or set to true, it will be included.
133+
/// </summary>
134+
private static async Task<bool> ShouldDeployToNanoDeviceAsync(IAssemblyReference assembly)
135+
{
136+
string value = await assembly.Metadata.GetEvaluatedPropertyValueAsync("DeployToNanoDevice");
137+
return string.IsNullOrEmpty(value) || !value.Equals("false", StringComparison.OrdinalIgnoreCase);
138+
}
139+
128140
/// <summary>
129141
/// Gets the full path to the compiled output of a <see cref="ConfiguredProject"/>.
130142
/// </summary>

0 commit comments

Comments
 (0)