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
3 changes: 2 additions & 1 deletion Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@
<!-- Include SourcePackage.editorconfig in all source packages. -->
<Target Name="_AddEditorConfigToSourcePackage">
<ItemGroup>
<TfmSpecificPackageFile Include="$(MSBuildThisFileDirectory)eng\SourcePackage.editorconfig" PackagePath="contentFiles/cs/$(TargetFramework)/.editorconfig" Condition="'$(TargetFrameworkIdentifier)' != '.NETStandard'" />
<TfmSpecificPackageFile Include="$(MSBuildThisFileDirectory)eng\SourcePackage.editorconfig" PackagePath="contentFiles/cs/$(TargetFramework)/.editorconfig" Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'" />
<TfmSpecificPackageFile Include="$(MSBuildThisFileDirectory)eng\SourcePackage.netstandard.editorconfig" PackagePath="contentFiles/cs/$(TargetFramework)/.editorconfig" Condition="'$(TargetFrameworkIdentifier)' == '.NETStandard'" />
<TfmSpecificPackageFile Include="$(MSBuildThisFileDirectory)eng\SourcePackage.netframework.editorconfig" PackagePath="contentFiles/cs/$(TargetFramework)/.editorconfig" Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'" />
</ItemGroup>
</Target>

Expand Down
1 change: 0 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="$(MicrosoftExtensionsLoggingAbstractionsVersion)" />
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="$(MicrosoftExtensionsLoggingConsoleVersion)" />
<PackageVersion Include="Microsoft.Extensions.ObjectPool" Version="$(MicrosoftExtensionsObjectPoolPackageVersion)" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Ini" Version="$(MicrosoftExtensionsConfigurationIniVersion)" />
<PackageVersion Include="Microsoft.FSharp.Compiler" Version="$(MicrosoftFSharpCompilerPackageVersion)" />
<PackageVersion Include="Microsoft.Net.Compilers.Toolset.Framework" Version="$(MicrosoftNetCompilersToolsetFrameworkPackageVersion)" />
<PackageVersion Include="Microsoft.Management.Infrastructure" Version="3.0.0" />
Expand Down
21 changes: 21 additions & 0 deletions eng/SourcePackage.netframework.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Remove the line below if you want to inherit .editorconfig settings from higher directories
root = true

# C# files
[*.cs]

# We don't want any analyzer diagnostics to be reported for people consuming this as a source package.
dotnet_analyzer_diagnostic.severity = none

generated_code = true

# The above configurations don't apply to compiler warnings. Requiring all params to be documented
# is not something we require for this project, so suppressing it directly here.
dotnet_diagnostic.CS1573.severity = none

# As above, we need to specifically disable compiler warnings that we don't want to break downstream
# builds
dotnet_diagnostic.IDE0005.severity = none

# Disable nullability checks when targeting .NET Framework
dotnet_diagnostic.CS8604.severity = none
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@ protected static string GetInjectedAssemblyPath(string targetFramework, string a

public static string GetStartupHookPath(ProjectGraphNode project)
{
var hookTargetFramework = project.GetTargetFramework() switch
{
// Note: Hot Reload is only supported on net6.0+
"net6.0" or "net7.0" or "net8.0" or "net9.0" => "net6.0",
_ => "net10.0",
};

var hookTargetFramework = project.GetTargetFrameworkVersion() is { Major: >= 10 } ? "net10.0" : "net6.0";
return GetInjectedAssemblyPath(hookTargetFramework, "Microsoft.Extensions.DotNetDeltaApplier");
}

Expand Down
1 change: 0 additions & 1 deletion src/Cli/Microsoft.TemplateEngine.Cli/Components.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public static class Components
(typeof(IPostActionProcessor), new InstructionDisplayPostActionProcessor()),
(typeof(IPostActionProcessor), new ProcessStartPostActionProcessor()),
(typeof(IPostActionProcessor), new AddJsonPropertyPostActionProcessor()),
(typeof(IPostActionProcessor), new CreateOrUpdateDotnetConfigPostActionProcessor()),
};
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 1 addition & 20 deletions src/Cli/Microsoft.TemplateEngine.Cli/LocalizableStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -953,23 +953,4 @@ The header is followed by the list of parameters and their errors (might be seve
<data name="PostAction_ModifyJson_Verbose_AttemptingToFindJsonFile" xml:space="preserve">
<value>Attempting to find json file '{0}' in '{1}'</value>
</data>
<data name="PostAction_DotnetConfig_Error_ArgumentNotConfigured" xml:space="preserve">
<value>Post action argument '{0}' is mandatory, but not configured.</value>
</data>
<data name="PostAction_CreateDotnetConfig_Succeeded" xml:space="preserve">
<value>Successfully created 'dotnet.config' file.</value>
<comment>{Locked="dotnet.config"}</comment>
</data>
<data name="PostAction_CreateDotnetConfig_CreatedNewSection" xml:space="preserve">
<value>Created new section in 'dotnet.config' file</value>
<comment>{Locked="dotnet.config"}</comment>
</data>
<data name="PostAction_CreateDotnetConfig_ValueAlreadyExist" xml:space="preserve">
<value>The required value in 'dotnet.config' is already set.</value>
<comment>{Locked="dotnet.config"}</comment>
</data>
<data name="PostAction_CreateDotnetConfig_ManuallyUpdate" xml:space="preserve">
<value>Updating existing values in 'dotnet.config' is not yet supported. Please, manually update 'dotnet.config' to have '{0}' under section '{1}'.</value>
<comment>{Locked="dotnet.config"}</comment>
</data>
</root>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<PackageReference Include="Microsoft.TemplateEngine.Edge" />
<PackageReference Include="Microsoft.TemplateSearch.Common" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" />
<PackageReference Include="Microsoft.Extensions.Configuration.Ini" />
<PackageReference Include="Wcwidth.Sources" ExcludeAssets="all" GeneratePathProperty="true" />
<PackageReference Include="System.CommandLine" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ internal class AddJsonPropertyPostActionProcessor : PostActionProcessorBase
private const string ParentPropertyPathArgument = "parentPropertyPath";
private const string NewJsonPropertyNameArgument = "newJsonPropertyName";
private const string NewJsonPropertyValueArgument = "newJsonPropertyValue";
private const string DetectRepoRootForFileCreation = "detectRepositoryRootForFileCreation";

private static readonly JsonSerializerOptions SerializerOptions = new()
{
Expand All @@ -36,6 +37,43 @@ internal class AddJsonPropertyPostActionProcessor : PostActionProcessorBase

internal static Guid ActionProcessorId { get; } = new Guid("695A3659-EB40-4FF5-A6A6-C9C4E629FCB0");

internal static string GetRootDirectory(IPhysicalFileSystem fileSystem, string outputBasePath)
{
string? currentDirectory = outputBasePath;
string? directoryWithSln = null;
while (currentDirectory is not null)
{
if (fileSystem.FileExists(Path.Combine(currentDirectory, "global.json")) ||
fileSystem.FileExists(Path.Combine(currentDirectory, ".git")) ||
fileSystem.DirectoryExists(Path.Combine(currentDirectory, ".git")))
{
// If we found global.json or .git, we immediately return the directory as the repo root.
// We won't go up any further.
return currentDirectory;
}

// DirectoryExists here should always be true in practice, but for the way tests are mocking the file system, it's not.
// The check was added to prevent test failures similar to:
// System.IO.DirectoryNotFoundException : Could not find a part of the path '/Users/runner/work/1/s/artifacts/bin/Microsoft.TemplateEngine.Cli.UnitTests/Release/sandbox'.
// We get to this exception when doing `EnumerateFiles` on a directory that was virtually created in memory (not really available on disk).
// EnumerateFiles tries to access the physical file system, which then fails.
if (fileSystem.DirectoryExists(currentDirectory) &&
(fileSystem.EnumerateFiles(currentDirectory, "*.sln", SearchOption.TopDirectoryOnly).Any() ||
fileSystem.EnumerateFiles(currentDirectory, "*.slnx", SearchOption.TopDirectoryOnly).Any()))
{
directoryWithSln = currentDirectory;
}

currentDirectory = Directory.GetParent(currentDirectory)?.FullName;
}

// If we reach here, that means we didn't find .git or global.json.
// So, we return the directory where we found a .sln/.slnx file, if any.
// Note that when we keep track of directoryWithSln, we keep updating it from sln/slnx from parent directories, if found.
// This means that if there are multiple .sln/.slnx files in the parent directories, we will return the top-most one.
return directoryWithSln ?? outputBasePath;
}

protected override bool ProcessInternal(
IEngineEnvironmentSettings environment,
IPostAction action,
Expand Down Expand Up @@ -65,7 +103,13 @@ protected override bool ProcessInternal(
return false;
}

string newJsonFilePath = Path.Combine(outputBasePath, jsonFileName);
if (!bool.TryParse(action.Args.GetValueOrDefault(DetectRepoRootForFileCreation, "false"), out bool detectRepoRoot))
{
Reporter.Error.WriteLine(string.Format(LocalizableStrings.PostAction_ModifyJson_Error_ArgumentNotBoolean, DetectRepoRootForFileCreation));
return false;
}

string newJsonFilePath = Path.Combine(detectRepoRoot ? GetRootDirectory(environment.Host.FileSystem, outputBasePath) : outputBasePath, jsonFileName);
environment.Host.FileSystem.WriteAllText(newJsonFilePath, "{}");
jsonFiles = new List<string> { newJsonFilePath };
}
Expand Down

This file was deleted.

Loading