Skip to content
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
39 changes: 39 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,29 @@ stages:
# displayName: 'Publish Quality Gate Result'
# continueOnError: true

- task: VisualStudioTestPlatformInstaller@1
condition: succeeded()
displayName: 'Install VS Test Platform'
inputs:
versionSelector: latestStable

- task: VSTest@2
condition: succeeded()
displayName: 'Running Unit Tests'
continueOnError: false
inputs:
testSelector: 'testAssemblies'
testAssemblyVer2: |
**\*Tests*.dll
!**\obj\**
!**\TestAdapter\**
searchFolder: '$(System.DefaultWorkingDirectory)'
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
diagnosticsEnabled: true
vsTestVersion: toolsInstaller
codeCoverageEnabled: true

- task: DotNetCoreCLI@2
displayName: Install Sign Client CLI
condition: >-
Expand Down Expand Up @@ -220,6 +243,22 @@ stages:
command: 'build'
projects: 'test/SmokeTest/SmokeTest.csproj'
arguments: '--configuration $(buildConfiguration) --no-restore'

- task: PowerShell@2
displayName: Validate SmokeTest native checksum
inputs:
targetType: inline
script: |
$expectedChecksum = '0x1DA81E42'
$actualChecksum = $env:NF_NATIVE_ASSEMBLY_CHECKSUM

if ($actualChecksum -ine $expectedChecksum)
{
Write-Host "##vso[task.logissue type=error]Smoke test assembly checksum mismatch: expected $expectedChecksum but got '$actualChecksum'."
exit 1
}

Write-Host "Smoke test assembly checksum matches expected value: $expectedChecksum."

- task: NuGetCommand@2
condition: >-
Expand Down
6 changes: 6 additions & 0 deletions nanoFramework.NET.Sdk.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "nanoFramework.Tools.BuildTa
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "nanoFramework.NET.Sdk", "nanoFramework.NET.Sdk\nanoFramework.NET.Sdk.csproj", "{B2C3D4E5-F6A7-8901-BCDE-F12345678901}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BuildTasks.Tests", "test\BuildTasks.Tests\BuildTasks.Tests.csproj", "{C3D4E5F6-A7B8-9012-CDEF-123456789012}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,5 +23,9 @@ Global
{B2C3D4E5-F6A7-8901-BCDE-F12345678901}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B2C3D4E5-F6A7-8901-BCDE-F12345678901}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B2C3D4E5-F6A7-8901-BCDE-F12345678901}.Release|Any CPU.Build.0 = Release|Any CPU
{C3D4E5F6-A7B8-9012-CDEF-123456789012}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C3D4E5F6-A7B8-9012-CDEF-123456789012}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C3D4E5F6-A7B8-9012-CDEF-123456789012}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C3D4E5F6-A7B8-9012-CDEF-123456789012}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
54 changes: 50 additions & 4 deletions nanoFramework.NET.Sdk/Sdk/nanoFramework.Resources.targets
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,61 @@
Condition="'$(NF_MSBUILDTASK_PATH)' != ''"
AssemblyFile="$(NF_MSBUILDTASK_PATH)\nanoFramework.Tools.BuildTasks.dll" />

<!--
Suppress the standard resource pipeline for nanoFramework .resx items.

The standard CoreResGen target (Microsoft.Common.CurrentVersion.targets) runs the
GenerateResource task, which rejects non-string resources (bitmaps, binary blobs)
unless the project references System.Resources.Extensions — an assembly that does
not exist in the nanoFramework BCL, and whose .resources output nanoFramework never
consumes anyway (the MetadataProcessor imports our .nanoresources directly, see
nanoFramework.Mdp.targets ImportResources).

We move the .resx items out of @(EmbeddedResource) into the private @(_NanoResxItems)
before CoreResGen runs, so the standard task never sees them
(no MSB3822/MSB3823, no dead .resources in the IL).
NanoGenerateResources then converts @(_NanoResxItems) into .nanoresources.

Runs before CoreResGen (so the items are gone by the time it executes) but after
PrepareResourceNames (so %(ManifestResourceName) is already assigned for the
output path below).
-->
<Target Name="_NanoInterceptResxItems" BeforeTargets="CoreResGen">
<ItemGroup>
<_NanoResxItems Include="@(EmbeddedResource)"
Condition="'%(EmbeddedResource.Type)' == 'Resx'" />
<EmbeddedResource Remove="@(_NanoResxItems)" />
</ItemGroup>
</Target>

<!--
Emit a build error when .resx resources are present but the project does not
reference nanoFramework.ResourceManager.

Set $(NanoSkipResourceManagerCheck) = true to suppress this error (e.g., in the
nanoFramework.ResourceManager package itself or any framework-level project that
provides resources without taking a self-reference).
-->
<Target Name="_NanoCheckResourceManagerRef"
Condition="'@(_NanoResxItems)' != '' AND '$(NanoSkipResourceManagerCheck)' != 'true'">
<ItemGroup>
<_NanoResManagerRef Include="@(PackageReference)"
Condition="'%(Identity)' == 'nanoFramework.ResourceManager'" />
</ItemGroup>
<Error Condition="'@(_NanoResManagerRef)' == ''"
Code="NFSDK0002"
Text="Projects that include .resx resources require a reference to the 'nanoFramework.ResourceManager' NuGet package. Add &lt;PackageReference Include=&quot;nanoFramework.ResourceManager&quot; /&gt; to your project file, or set &lt;NanoSkipResourceManagerCheck&gt;true&lt;/NanoSkipResourceManagerCheck&gt; to suppress this check." />
</Target>

<Target Name="NanoGenerateResources"
Condition="'@(EmbeddedResource)' != ''">
DependsOnTargets="_NanoInterceptResxItems;_NanoCheckResourceManagerRef">
<GenerateNanoResourceTask
Sources="@(EmbeddedResource)"
Condition="'%(EmbeddedResource.Type)' == 'Resx' and '%(EmbeddedResource.GenerateResource)' != 'false'"
Condition="'@(_NanoResxItems)' != ''"
Sources="@(_NanoResxItems)"
References="@(ReferencePath)"
UseSourcePath="$(UseSourcePath)"
StateFile="$(IntermediateOutputPath)$(MSBuildProjectFile).NanoGenerateResources.Cache"
OutputResources="@(EmbeddedResource->'$(IntermediateOutputPath)%(ManifestResourceName).nanoresources')">
OutputResources="@(_NanoResxItems->'$(IntermediateOutputPath)%(ManifestResourceName).nanoresources')">
Comment thread
coderabbitai[bot] marked this conversation as resolved.
<Output TaskParameter="OutputResources" ItemName="_NanoResources" />
<Output TaskParameter="FilesWritten" ItemName="FileWrites" />
</GenerateNanoResourceTask>
Expand Down
4 changes: 4 additions & 0 deletions nanoFramework.NET.Sdk/nanoFramework.NET.Sdk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@
<None Include="..\nanoFramework.Tools.BuildTasks\bin\$(Configuration)\net8.0\nanoFramework.Tools.BuildTasks.dll" Pack="true" PackagePath="tasks\net8.0" />
<None Include="..\nanoFramework.Tools.BuildTasks\bin\$(Configuration)\net8.0\nanoFramework.Tools.BuildTasks.pdb" Pack="true" PackagePath="tasks\net8.0" Condition="Exists('..\nanoFramework.Tools.BuildTasks\bin\$(Configuration)\net8.0\nanoFramework.Tools.BuildTasks.pdb')" />

<!-- Cross-platform resource-processing dependencies, loaded alongside the net8.0 task DLL -->
<None Include="..\nanoFramework.Tools.BuildTasks\bin\$(Configuration)\net8.0\SixLabors.ImageSharp.dll" Pack="true" PackagePath="tasks\net8.0" />
<None Include="..\nanoFramework.Tools.BuildTasks\bin\$(Configuration)\net8.0\System.CodeDom.dll" Pack="true" PackagePath="tasks\net8.0" />

<!-- Package README -->
<None Include="..\README.md" Pack="true" PackagePath="" />
</ItemGroup>
Expand Down
98 changes: 98 additions & 0 deletions nanoFramework.Tools.BuildTasks/GenerateBinaryOutputTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
//
// Copyright (c) .NET Foundation and Contributors
// Portions Copyright (c) Microsoft Corporation. All rights reserved.
// See LICENSE file in the project root for full license information.
//

using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using nanoFramework.Tools.Utilities;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;

namespace nanoFramework.Tools
{
[Description("GenerateBinaryOutputTaskEntry")]

public class GenerateBinaryOutputTask : Task
{
#region public properties for the task

public string Assembly { get; set; }

public string AssemblyPE { get; set; }

public ITaskItem[] AssemblyReferences { get; set; }


/// <summary>
/// The name(s) of binary file created.
/// </summary>
[Output]
public ITaskItem FileWritten { get; private set; }

#endregion

public override bool Execute()
{
// report to VS output window what step the build is
Log.LogMessage(MessageImportance.Normal, "Generating binary output file...");

// wait for debugger on var
DebuggerHelper.WaitForDebuggerIfEnabled(TasksConstants.BuildTaskDebugVar);

// default with null, indicating that we've generated nothing
FileWritten = null;

// get paths for PE files
List<string> peCollection = AssemblyReferences?
.Select(a => Path.ChangeExtension(a.GetMetadata("FullPath"), ".pe"))
.ToList() ?? new List<string>();

// add executable PE
peCollection.Add(AssemblyPE);

// get executable path and file name
// rename executable extension .exe with .bin
var binOutputFile = Assembly.Replace(".exe", ".bin");

using (FileStream binFile = new FileStream(binOutputFile, FileMode.Create))
{
// now we will re-deploy all system assemblies
foreach (string peItem in peCollection)
{
// append to the deploy blob the assembly
using (FileStream fs = File.Open(peItem, FileMode.Open, FileAccess.Read, FileShare.Read))
{
long length = (fs.Length + 3) / 4 * 4;
byte[] buffer = new byte[length];
int fileLength = (int)fs.Length;
int totalRead = 0;

while (totalRead < fileLength)
{
int bytesRead = fs.Read(buffer, totalRead, fileLength - totalRead);

if (bytesRead == 0)
{
throw new EndOfStreamException($"Unexpected end of file while reading '{peItem}'.");
}

totalRead += bytesRead;
}

// copy this assembly to the bin file too
binFile.Write(buffer, 0, (int)length);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}
}
}

// bin file written
FileWritten = new TaskItem(binOutputFile);

return true;
}
}
}
53 changes: 0 additions & 53 deletions nanoFramework.Tools.BuildTasks/GenerateNanoResourceTask.Stub.cs

This file was deleted.

Loading