Skip to content

Commit 0cfc81c

Browse files
authored
Add MSBuild task with MDP (#128)
1 parent 98b12ea commit 0cfc81c

12 files changed

+755
-20
lines changed

MetadataProcessor.MsBuildTask/MetaDataProcessorTask.cs

Lines changed: 442 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="$(VisualStudioVersion)" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{9B18784E-1BF2-47D1-BDD1-85B678F883F9}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>nanoFramework.Tools.MetadataProcessor.MsBuildTask</RootNamespace>
11+
<AssemblyName>nanoFramework.Tools.MetadataProcessor.MsBuildTask</AssemblyName>
12+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<NuGetPackageImportStamp>
15+
</NuGetPackageImportStamp>
16+
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
17+
<Deterministic>true</Deterministic>
18+
<EmbedUntrackedSources>true</EmbedUntrackedSources>
19+
<ContinuousIntegrationBuild Condition="'$(TF_BUILD)' == 'true'">True</ContinuousIntegrationBuild>
20+
</PropertyGroup>
21+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
22+
<DebugSymbols>true</DebugSymbols>
23+
<DebugType>full</DebugType>
24+
<Optimize>false</Optimize>
25+
<OutputPath>bin\Debug\</OutputPath>
26+
<DefineConstants>DEBUG;TRACE</DefineConstants>
27+
<ErrorReport>prompt</ErrorReport>
28+
<WarningLevel>4</WarningLevel>
29+
</PropertyGroup>
30+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
31+
<DebugType>portable</DebugType>
32+
<Optimize>true</Optimize>
33+
<OutputPath>bin\Release\</OutputPath>
34+
<DefineConstants>TRACE</DefineConstants>
35+
<ErrorReport>prompt</ErrorReport>
36+
<WarningLevel>4</WarningLevel>
37+
</PropertyGroup>
38+
<ItemGroup>
39+
<Reference Include="Microsoft.Build.Framework" />
40+
<Reference Include="Microsoft.Build.Utilities.v4.0" />
41+
<Reference Include="System" />
42+
<Reference Include="System.Core" />
43+
<Reference Include="System.Xml.Linq" />
44+
<Reference Include="System.Data.DataSetExtensions" />
45+
<Reference Include="Microsoft.CSharp" />
46+
<Reference Include="System.Data" />
47+
<Reference Include="System.Net.Http" />
48+
<Reference Include="System.Xml" />
49+
</ItemGroup>
50+
<ItemGroup>
51+
<Compile Include="TasksConstants.cs" />
52+
<Compile Include="MetaDataProcessorTask.cs" />
53+
<Compile Include="Properties\AssemblyInfo.cs" />
54+
<Compile Include="Utilities\DebuggerHelper.cs" />
55+
</ItemGroup>
56+
<ItemGroup>
57+
<ProjectReference Include="..\MetadataProcessor.Core\MetadataProcessor.Core.csproj">
58+
<Project>{e32f7d15-2499-440c-8026-4d5ee1c5ec3a}</Project>
59+
<Name>MetadataProcessor.Core</Name>
60+
</ProjectReference>
61+
</ItemGroup>
62+
<ItemGroup>
63+
<None Include="packages.lock.json" />
64+
</ItemGroup>
65+
<ItemGroup>
66+
<PackageReference Include="Microsoft.SourceLink.GitHub">
67+
<Version>1.0.0</Version>
68+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
69+
<PrivateAssets>all</PrivateAssets>
70+
</PackageReference>
71+
<PackageReference Include="Mono.Cecil">
72+
<Version>0.11.3</Version>
73+
</PackageReference>
74+
<PackageReference Include="mustache-sharp">
75+
<Version>1.0.0</Version>
76+
</PackageReference>
77+
<PackageReference Include="Nerdbank.GitVersioning">
78+
<Version>3.3.37</Version>
79+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
80+
<PrivateAssets>all</PrivateAssets>
81+
</PackageReference>
82+
</ItemGroup>
83+
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
84+
</Project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle(".NET nanoFramework Metadata processor MSBuild Task library")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("nanoFramework")]
12+
[assembly: AssemblyProduct(".NET nanoFramework Metadata processor MSBuild Task library")]
13+
[assembly: AssemblyCopyright("Copyright © 2020 nanoFramework contributors")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// Copyright (c) .NET Foundation and Contributors
3+
// Portions Copyright (c) Microsoft Corporation. All rights reserved.
4+
// See LICENSE file in the project root for full license information.
5+
//
6+
7+
namespace nanoFramework.Tools
8+
{
9+
internal class TasksConstants
10+
{
11+
public const string BuildTaskDebugVar = "NFBUILD_TASKS_DEBUG";
12+
}
13+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//
2+
// Copyright (c) .NET Foundation and Contributors
3+
// Portions Copyright (c) Microsoft Corporation. All rights reserved.
4+
// See LICENSE file in the project root for full license information.
5+
//
6+
7+
using System;
8+
using System.Diagnostics;
9+
using System.Threading;
10+
11+
namespace nanoFramework.Tools.Utilities
12+
{
13+
internal static class DebuggerHelper
14+
{
15+
public static void WaitForDebuggerIfEnabled(string varName, int timeoutSeconds = 30)
16+
{
17+
18+
// this wait should be only available on debug build
19+
// to prevent unwanted wait on VS in machines where the variable is present
20+
#if DEBUG
21+
TimeSpan waitForDebugToAttach = TimeSpan.FromSeconds(timeoutSeconds);
22+
23+
var debugEnabled = Environment.GetEnvironmentVariable(varName, EnvironmentVariableTarget.User);
24+
25+
if (!string.IsNullOrEmpty(debugEnabled) && debugEnabled.Equals("1", StringComparison.Ordinal))
26+
{
27+
Console.WriteLine($".NET nanoFramework Metadata Processor msbuild instrumentation task debugging is enabled. Waiting {timeoutSeconds} seconds for debugger attachment...");
28+
29+
var currentProcessId = Process.GetCurrentProcess().Id;
30+
var currentProcessName = Process.GetProcessById(currentProcessId).ProcessName;
31+
Console.WriteLine(
32+
string.Format("Process Id: {0}, Name: {1}", currentProcessId, currentProcessName)
33+
);
34+
35+
// wait N seconds for debugger to attach
36+
while (!Debugger.IsAttached && waitForDebugToAttach.TotalSeconds > 0)
37+
{
38+
Thread.Sleep(1000);
39+
waitForDebugToAttach -= TimeSpan.FromSeconds(1);
40+
}
41+
42+
Debugger.Break();
43+
}
44+
#endif
45+
}
46+
}
47+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<ItemGroup>
3+
<Content Include="$(OutDir)nanoFramework.Tools.MetadataProcessor.Core.dll">
4+
<InstallRoot>MSBuild</InstallRoot>
5+
<VSIXSubPath>nanoFramework\v1.0\</VSIXSubPath>
6+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
7+
<IncludeInVSIX>true</IncludeInVSIX>
8+
</Content>
9+
<Content Include="$(OutDir)nanoFramework.Tools.MetadataProcessor.MsBuildTask.dll">
10+
<InstallRoot>MSBuild</InstallRoot>
11+
<VSIXSubPath>nanoFramework\v1.0\</VSIXSubPath>
12+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
13+
<IncludeInVSIX>true</IncludeInVSIX>
14+
</Content>
15+
<Content Include="$(OutDir)Mono.Cecil.dll">
16+
<InstallRoot>MSBuild</InstallRoot>
17+
<VSIXSubPath>nanoFramework\v1.0\</VSIXSubPath>
18+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
19+
<IncludeInVSIX>true</IncludeInVSIX>
20+
</Content>
21+
<Content Include="$(OutDir)Mono.Cecil.Pdb.dll">
22+
<InstallRoot>MSBuild</InstallRoot>
23+
<VSIXSubPath>nanoFramework\v1.0\</VSIXSubPath>
24+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
25+
<IncludeInVSIX>true</IncludeInVSIX>
26+
</Content>
27+
<Content Include="$(OutDir)Mono.Cecil.Rocks.dll">
28+
<InstallRoot>MSBuild</InstallRoot>
29+
<VSIXSubPath>nanoFramework\v1.0\</VSIXSubPath>
30+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
31+
<IncludeInVSIX>true</IncludeInVSIX>
32+
</Content>
33+
<Content Include="$(OutDir)mustache-sharp.dll">
34+
<InstallRoot>MSBuild</InstallRoot>
35+
<VSIXSubPath>nanoFramework\v1.0\</VSIXSubPath>
36+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
37+
<IncludeInVSIX>true</IncludeInVSIX>
38+
</Content>
39+
</ItemGroup>
40+
</Project>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0"?>
2+
<package >
3+
<metadata>
4+
<id>nanoFramework.Tools.MetadataProcessor.MsBuildTask</id>
5+
<title>nanoFramework.Tools.MetadataProcessor.MsBuildTask</title>
6+
<version>$version$</version>
7+
<authors>nanoFramework project contributors</authors>
8+
<owners>nanoFramework project contributors,dotnetfoundation</owners>
9+
<description>
10+
Metadata Processor MSBuild task to be used internally by the VS nanoFramework extension.
11+
</description>
12+
<releaseNotes>
13+
</releaseNotes>
14+
<projectUrl>https://github.com/nanoframework/metadata-processor</projectUrl>
15+
<icon>images\nf-logo.png</icon>
16+
<license type="file">LICENSE.md</license>
17+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
18+
<repository type="git" url="https://github.com/nanoframework/metadata-processor" commit="$commit$" />
19+
<copyright>Copyright (c) .NET Foundation and Contributors</copyright>
20+
<references></references>
21+
<tags>nanoFramework, nano Framework, NETNF, NETMF, Micro Framework, .net</tags>
22+
<dependencies>
23+
<dependency id="Mono.Cecil" version="0.11.3" />
24+
<dependency id="mustache-sharp" version="1.0.0" />
25+
</dependencies>
26+
</metadata>
27+
<files>
28+
<file src="bin\Release\nanoFramework.Tools.MetadataProcessor.Core.dll" target="lib/net472" />
29+
<file src="bin\Release\nanoFramework.Tools.MetadataProcessor.MsBuildTask.dll" target="lib/net472" />
30+
<file src="nanoFramework.Tools.MetadataProcessor.MsBuildTask.targets" target="build" />
31+
<file src="..\nf-logo.png" target="images\" />
32+
<file src="..\LICENSE.md" target="" />
33+
</files>
34+
</package>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"version": 1,
3+
"dependencies": {
4+
".NETFramework,Version=v4.7.2": {
5+
"Microsoft.SourceLink.GitHub": {
6+
"type": "Direct",
7+
"requested": "[1.0.0, )",
8+
"resolved": "1.0.0",
9+
"contentHash": "aZyGyGg2nFSxix+xMkPmlmZSsnGQ3w+mIG23LTxJZHN+GPwTQ5FpPgDo7RMOq+Kcf5D4hFWfXkGhoGstawX13Q==",
10+
"dependencies": {
11+
"Microsoft.Build.Tasks.Git": "1.0.0",
12+
"Microsoft.SourceLink.Common": "1.0.0"
13+
}
14+
},
15+
"Mono.Cecil": {
16+
"type": "Direct",
17+
"requested": "[0.11.3, )",
18+
"resolved": "0.11.3",
19+
"contentHash": "DNYE+io5XfEE8+E+5padThTPHJARJHbz1mhbhMPNrrWGKVKKqj/KEeLvbawAmbIcT73NuxLV7itHZaYCZcVWGg=="
20+
},
21+
"mustache-sharp": {
22+
"type": "Direct",
23+
"requested": "[1.0.0, )",
24+
"resolved": "1.0.0",
25+
"contentHash": "+RTxWGLH5p0ibl7XDbb8pOznAdqwxH3zic40eL1gq5xl8jZt3CFc04KSLLFWM3PgvlTzfbzDJfjzF7rCglqGAA=="
26+
},
27+
"Nerdbank.GitVersioning": {
28+
"type": "Direct",
29+
"requested": "[3.3.37, )",
30+
"resolved": "3.3.37",
31+
"contentHash": "YlDKV/gSHQGDThWSGqVyPfKeNP/kx1fj/NPFFgGc/cxzgIbXv4jtYOcbFOz3ZIeAKtpCcSAmVNDOikBs3OxI/A=="
32+
},
33+
"Microsoft.Build.Tasks.Git": {
34+
"type": "Transitive",
35+
"resolved": "1.0.0",
36+
"contentHash": "z2fpmmt+1Jfl+ZnBki9nSP08S1/tbEOxFdsK1rSR+LBehIJz1Xv9/6qOOoGNqlwnAGGVGis1Oj6S8Kt9COEYlQ=="
37+
},
38+
"Microsoft.SourceLink.Common": {
39+
"type": "Transitive",
40+
"resolved": "1.0.0",
41+
"contentHash": "G8DuQY8/DK5NN+3jm5wcMcd9QYD90UV7MiLmdljSJixi3U/vNaeBKmmXUqI4DJCOeWizIUEh4ALhSt58mR+5eg=="
42+
},
43+
"metadataprocessor.core": {
44+
"type": "Project",
45+
"dependencies": {
46+
"Mono.Cecil": "0.11.3",
47+
"mustache-sharp": "1.0.0"
48+
}
49+
}
50+
},
51+
".NETFramework,Version=v4.7.2/win": {},
52+
".NETFramework,Version=v4.7.2/win-x64": {},
53+
".NETFramework,Version=v4.7.2/win-x86": {}
54+
}
55+
}

azure-pipelines.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ jobs:
121121
sourceFolder: $(Build.SourcesDirectory)
122122
Contents: |
123123
**\bin\Release\nanoFramework.Tools.MetaDataProcessor.exe
124+
**\bin\Release\nanoFramework.Tools.MetadataProcessor.MsBuildTask.dll
124125
TargetFolder: '$(Build.ArtifactStagingDirectory)'
125126
flattenFolders: true
126127

@@ -134,10 +135,10 @@ jobs:
134135

135136
- task: NuGetCommand@2
136137
condition: succeeded()
137-
displayName: Pack NuGet witj MDP tool
138+
displayName: Pack NuGet with MDP MSBuild task
138139
inputs:
139140
command: 'custom'
140-
arguments: 'pack MetadataProcessor.Core\package.nuspec -Version $(NBGV_NuGetPackageVersion) -properties commit="$(Build.SourceVersion)"'
141+
arguments: 'pack MetadataProcessor.MsBuildTask\package.nuspec -Version $(NBGV_NuGetPackageVersion) -properties commit="$(Build.SourceVersion)"'
141142

142143
- task: CopyFiles@1
143144
condition: succeeded()

azure-pipelines/update-dependencies.ps1

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,37 +35,29 @@ git checkout --quiet develop | Out-Null
3535
####################
3636
# VS 2017
3737

38-
Write-Host "Updating nanoFramework.Tools.MetadataProcessor.Core package in VS2017 solution..."
38+
Write-Host "Updating nanoFramework.Tools.MetadataProcessor.MsBuildTask package in VS2017 solution..."
3939

40-
dotnet remove Tools.BuildTasks\Tools.BuildTasks.csproj package nanoFramework.Tools.MetadataProcessor.Core
40+
dotnet remove VisualStudio.Extension\VisualStudio.Extension.csproj package nanoFramework.Tools.MetadataProcessor.MsBuildTask
4141

42-
dotnet add Tools.BuildTasks\Tools.BuildTasks.csproj package nanoFramework.Tools.MetadataProcessor.Core --prerelease -s https://pkgs.dev.azure.com/nanoframework/feed/_packaging/sandbox/nuget/v3/index.json
43-
44-
dotnet remove VisualStudio.Extension\VisualStudio.Extension.csproj package nanoFramework.Tools.MetadataProcessor.Core
45-
46-
dotnet add VisualStudio.Extension\VisualStudio.Extension.csproj package nanoFramework.Tools.MetadataProcessor.Core --prerelease -s https://pkgs.dev.azure.com/nanoframework/feed/_packaging/sandbox/nuget/v3/index.json
42+
dotnet add VisualStudio.Extension\VisualStudio.Extension.csproj package nanoFramework.Tools.MetadataProcessor.MsBuildTask --prerelease -s https://pkgs.dev.azure.com/nanoframework/feed/_packaging/sandbox/nuget/v3/index.json
4743

4844
####################
4945
# VS 2019
5046

51-
Write-Host "Updating nanoFramework.Tools.MetadataProcessor.Core package in VS2019 solution..."
52-
53-
dotnet remove Tools.BuildTasks-2019\Tools.BuildTasks.csproj package nanoFramework.Tools.MetadataProcessor.Core
54-
55-
dotnet add Tools.BuildTasks-2019\Tools.BuildTasks.csproj package nanoFramework.Tools.MetadataProcessor.Core --prerelease -s https://pkgs.dev.azure.com/nanoframework/feed/_packaging/sandbox/nuget/v3/index.json
47+
Write-Host "Updating nanoFramework.Tools.MetadataProcessor.MsBuildTask package in VS2019 solution..."
5648

57-
dotnet remove VisualStudio.Extension-2019\VisualStudio.Extension.csproj package nanoFramework.Tools.MetadataProcessor.Core
49+
dotnet remove VisualStudio.Extension-2019\VisualStudio.Extension.csproj package nanoFramework.Tools.MetadataProcessor.MsBuildTask
5850

59-
dotnet add VisualStudio.Extension-2019\VisualStudio.Extension.csproj package nanoFramework.Tools.MetadataProcessor.Core --prerelease -s https://pkgs.dev.azure.com/nanoframework/feed/_packaging/sandbox/nuget/v3/index.json
51+
dotnet add VisualStudio.Extension-2019\VisualStudio.Extension.csproj package nanoFramework.Tools.MetadataProcessor.MsBuildTask --prerelease -s https://pkgs.dev.azure.com/nanoframework/feed/_packaging/sandbox/nuget/v3/index.json
6052

6153
#####################
6254

63-
"Bumping MetadataProcessor.Core to $packageTargetVersion." | Write-Host -ForegroundColor Cyan
55+
"Bumping MetadataProcessor.MsBuildTask to $packageTargetVersion." | Write-Host -ForegroundColor Cyan
6456

6557
# build commit message
66-
$commitMessage += "Bumps MetadataProcessor.Core to $packageTargetVersion.`n"
58+
$commitMessage += "Bumps MetadataProcessor.MsBuildTask to $packageTargetVersion.`n"
6759
# build PR title
68-
$prTitle = "Bumps MetadataProcessor.Core to $packageTargetVersion"
60+
$prTitle = "Bumps MetadataProcessor.MsBuildTask to $packageTargetVersion"
6961

7062
# need this line so nfbot flags the PR appropriately
7163
$commitMessage += "`n[version update]`n`n"

0 commit comments

Comments
 (0)