Skip to content

Commit

Permalink
Merge pull request #17 from microsoft/dev/sknam/fix-warnings-and-upda…
Browse files Browse the repository at this point in the history
…te-copied-artifacts

Fix warnings and remove extra published artifacts
  • Loading branch information
skylarnam authored Feb 23, 2023
2 parents b759581 + 5f2acab commit 61ce03e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
2 changes: 1 addition & 1 deletion VSConfigFinder/CommandLine/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class CommandLineOptions : ICommandLineOptions
{
/// <inheritdoc/>
[Option("folderpath", Required = true, HelpText = "The source folder path to use as the root. The search will start from the root towards the bottom.")]
public IEnumerable<string> FolderPath { get; set; }
public IEnumerable<string>? FolderPath { get; set; }

/// <inheritdoc/>
[Option("createfile", Required = false, Default = false, HelpText = "(Default: false) Bool flag that indicates whether the output gets created as a consolidated .vsconfig file instead of the Visual Studio Installer setup command line arguments.\n" +
Expand Down
2 changes: 1 addition & 1 deletion VSConfigFinder/CommandLine/ICommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface ICommandLineOptions
/// <summary>
/// Gets or sets the folder paths to be used as the root (starting point) of the search.
/// </summary>
IEnumerable<string> FolderPath { get; set; }
IEnumerable<string>? FolderPath { get; set; }

/// <summary>
/// Gets or sets the value indicating whether the output gets created as a consolidated .vsconfig file instead of the Visual Studio Installer setup command line arguments.
Expand Down
18 changes: 18 additions & 0 deletions VSConfigFinder/CommandLine/SourceGenerationContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// <copyright file="SourceGenerationContext.cs" company="Microsoft Corporation">
// Copyright (C) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt in the project root for license information.
// </copyright>

namespace VSConfigFinder
{
using System.Text.Json.Serialization;

/// <summary>
/// Creates a <see cref="JsonSerializerContext"/> for serializing/deserializing .vsconfigs.
/// </summary>
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(VSConfig))]
internal partial class SourceGenerationContext : JsonSerializerContext
{
}
}
16 changes: 12 additions & 4 deletions VSConfigFinder/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ public static void CreateOutput(IFileSystem fileSystem, ILogger logger, VSConfig
if (options.CreateFile)
{
// Create a file
var serializerOptions = new JsonSerializerOptions { WriteIndented = true };
var jsonString = JsonSerializer.Serialize(finalConfig, serializerOptions);
var jsonString = JsonSerializer.Serialize(finalConfig, typeof(VSConfig), SourceGenerationContext.Default);
var outputPath = Path.Combine(options.ConfigOutputPath!, ConfigExtension);

fileSystem.WriteAllText(outputPath, jsonString);
Expand All @@ -91,21 +90,30 @@ public static void CreateOutput(IFileSystem fileSystem, ILogger logger, VSConfig
/// <returns></returns>
public static string[] ReadComponents(IFileSystem fileSystem, CommandLineOptions options)
{
var pathsToVsConfigs = fileSystem.GetFileSystemEntries(options.FolderPath, "*" + ConfigExtension, recursive: true);
var pathsToVsConfigs = fileSystem.GetFileSystemEntries(options.FolderPath!, "*" + ConfigExtension, recursive: true);

var componentsSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
var serializerOptions = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
AllowTrailingCommas = true,
};
var context = new SourceGenerationContext(serializerOptions);

foreach (var path in pathsToVsConfigs)
{
string[]? components;
using (var stream = fileSystem.OpenFile(path))
{
components = JsonSerializer.Deserialize<VSConfig>(stream, serializerOptions)?.Components;
var config = JsonSerializer.Deserialize(stream, typeof(VSConfig), context);
if (config is VSConfig vsconfig)
{
components = vsconfig.Components;
}
else
{
throw new ArgumentException("Failed to read components. Please make sure the .vsconfig file input is in the correct format.");
}
}

if (components is not null)
Expand Down
6 changes: 3 additions & 3 deletions vsts-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ steps:
zipAfterPublish: false

- task: CopyFiles@2
displayName: 'Copy build artifacts from: $(Build.SourcesDirectory)\VSConfigFinder\bin\$(BuildConfiguration)\** to $(Build.ArtifactStagingDirectory)\out'
displayName: 'Copy build artifacts'
inputs:
SourceFolder: $(Build.SourcesDirectory)\VSConfigFinder
Contents: |
bin\$(BuildConfiguration)\**
bin\$(BuildConfiguration)\**\publish\*
TargetFolder: $(Build.ArtifactStagingDirectory)\out

- task: PublishBuildArtifacts@1
displayName: 'Publish build artifacts from: $(Build.ArtifactStagingDirectory)\out'
displayName: 'Publish build artifacts'
inputs:
PathtoPublish: $(Build.ArtifactStagingDirectory)\out
ArtifactName: drop
Expand Down

0 comments on commit 61ce03e

Please sign in to comment.