Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
6 changes: 5 additions & 1 deletion src/Tasks/Common/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -956,5 +956,9 @@ You may need to build the project on another operating system or architecture, o
<value>NETSDK1216: Package Microsoft.Net.Sdk.Compilers.Toolset is not downloaded but it is needed because your MSBuild and SDK versions are mismatched. Ensure version {0} of the package is available in your NuGet source feeds and then run NuGet package restore from Visual Studio or MSBuild.</value>
<comment>{StrBegin="NETSDK1216: "}{Locked="Microsoft.Net.Sdk.Compilers.Toolset"} {0} is a NuGet package version and should not be translated.</comment>
</data>
<!-- The latest message added is MicrosoftNetSdkCompilersToolsetNotFound. Please update this value with each PR to catch parallel PRs both adding a new message -->
<data name="InvalidAppHostDotNetSearch" xml:space="preserve">
<value>NETSDK1217: Invalid value in AppHostDotNetSearch: '{0}'.</value>
<comment>{StrBegin="NETSDK1217: "}</comment>
</data>
<!-- The latest message added is InvalidAppHostDotNetSearch. Please update this value with each PR to catch parallel PRs both adding a new message -->
</root>
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.cs.xlf

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

5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.de.xlf

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

5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.es.xlf

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

5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.fr.xlf

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

5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.it.xlf

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

5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.ja.xlf

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

5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.ko.xlf

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

5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.pl.xlf

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

5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf

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

5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.ru.xlf

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

5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.tr.xlf

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

5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf

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

5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf

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

31 changes: 30 additions & 1 deletion src/Tasks/Microsoft.NET.Build.Tasks/CreateAppHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public class CreateAppHost : TaskBase

public bool DisableCetCompat { get; set; } = false;

public ITaskItem[] DotNetSearchLocations { get; set; }

public string AppRelativeDotNet { get; set; } = null;

protected override void ExecuteCore()
{
try
Expand All @@ -61,13 +65,38 @@ protected override void ExecuteCore()
{
try
{
HostWriter.DotNetSearchOptions options = null;
if (DotNetSearchLocations?.Length > 0)
{
HostWriter.DotNetSearchOptions.SearchLocation searchLocation = default;
foreach (var locationItem in DotNetSearchLocations)
{
if (Enum.TryParse(locationItem.ItemSpec, out HostWriter.DotNetSearchOptions.SearchLocation location)
&& Enum.IsDefined(typeof(HostWriter.DotNetSearchOptions.SearchLocation), location))
{
searchLocation |= location;
}
else
{
throw new BuildErrorException(Strings.InvalidAppHostDotNetSearch, locationItem.ItemSpec);
}
}

options = new HostWriter.DotNetSearchOptions()
{
Location = searchLocation,
AppRelativeDotNet = AppRelativeDotNet
};
}

HostWriter.CreateAppHost(appHostSourceFilePath: AppHostSourcePath,
appHostDestinationFilePath: AppHostDestinationPath,
appBinaryFilePath: AppBinaryName,
windowsGraphicalUserInterface: isGUI,
assemblyToCopyResourcesFrom: resourcesAssembly,
enableMacOSCodeSign: EnableMacOSCodeSign,
disableCetCompat: DisableCetCompat);
disableCetCompat: DisableCetCompat,
dotNetSearchOptions: options);
return;
}
catch (Exception ex) when (ex is IOException ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,33 @@ Copyright (c) .NET Foundation. All rights reserved.
/>
</Target>

<!--
============================================================
_CreateAppHostForPublish
Create the apphost for the publish scenario if app is configuring .NET install search behaviour
Because there is no SDK support yet for output with a layout conforming to the configuration,
only do this on publish, such that the inner dev loop is unaffected.
============================================================
-->
<Target Name="_CreateAppHostForPublish"
DependsOnTargets="_GetAppHostPaths;_GetAppHostCreationConfiguration"
Condition="'$(_UpdateAppHostForPublish)' == 'true' and
Exists('@(IntermediateAssembly)') and
Exists('$(AppHostSourcePath)')">
<CreateAppHost AppHostSourcePath="$(AppHostSourcePath)"
AppHostDestinationPath="$(AppHostIntermediatePath)"
AppBinaryName="$(AssemblyName)$(TargetExt)"
IntermediateAssembly="@(IntermediateAssembly->'%(FullPath)')"
WindowsGraphicalUserInterface="$(_UseWindowsGraphicalUserInterface)"
Retries="$(CopyRetryCount)"
RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)"
EnableMacOSCodeSign="$(_EnableMacOSCodeSign)"
DisableCetCompat="$(_DisableCetCompat)"
DotNetSearchLocations="$(AppHostDotNetSearch)"
AppRelativeDotNet="$(AppHostRelativeDotNet)"
/>
</Target>

<!--
============================================================
_ComputeCopyToPublishDirectoryItems
Expand Down Expand Up @@ -762,6 +789,7 @@ Copyright (c) .NET Foundation. All rights reserved.
DependsOnTargets="AssignTargetPaths;
DefaultCopyToPublishDirectoryMetadata;
_CreateSingleFileHost;
_CreateAppHostForPublish;
_SplitProjectReferencesByFileExistence;
_GetProjectReferenceTargetFrameworkProperties">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,11 @@ Copyright (c) .NET Foundation. All rights reserved.
'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and
$([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), 5.0))">true</_UseSingleFileHostForPublish>
<_DisableCetCompat Condition="'$(CetCompat)' == 'false'">true</_DisableCetCompat>

<!-- Default to AppHostDotNetSearch=AppRelative if AppHostRelativeDotNet is set -->
<AppHostDotNetSearch Condition="'$(AppHostRelativeDotNet)' != '' and '$(AppHostDotNetSearch)' == ''">AppRelative</AppHostDotNetSearch>
<_UpdateAppHostForPublish Condition="'$(_UseSingleFileHostForPublish)' != 'true' and
('$(AppHostRelativeDotNet)' != '' or '$(AppHostDotNetSearch)' != '')">true</_UpdateAppHostForPublish>
</PropertyGroup>
</Target>

Expand Down
34 changes: 34 additions & 0 deletions test/Microsoft.NET.Build.Tests/AppHostTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,40 @@ public void It_can_disable_cetcompat(bool? cetCompat)
isCetCompatible.Should().Be(!cetCompat.HasValue || cetCompat.Value);
}

[Fact]
public void It_does_not_configure_dotnet_search_options_on_build()
{
var targetFramework = ToolsetInfo.CurrentTargetFramework;
var runtimeIdentifier = EnvironmentInfo.GetCompatibleRid(targetFramework);

var testProject = new TestProject()
{
Name = "AppHostDotNetSearch",
TargetFrameworks = targetFramework,
RuntimeIdentifier = runtimeIdentifier,
IsExe = true,
};
testProject.AdditionalProperties.Add("AppHostDotNetSearch", "AppRelative");
testProject.AdditionalProperties.Add("AppHostRelativeDotNet", "subdirectory");

var testAsset = _testAssetsManager.CreateTestProject(testProject);

var buildCommand = new BuildCommand(testAsset);
buildCommand.Execute()
.Should()
.Pass();

// Output apphost should not have .NET search location options changed, so it
// should run successfully with the DOTNET_ROOT environment variable set
var outputDirectory = buildCommand.GetOutputDirectory(runtimeIdentifier: runtimeIdentifier);
outputDirectory.Should().HaveFiles(new[] { $"{testProject.Name}{Constants.ExeSuffix}" });
new RunExeCommand(Log, Path.Combine(outputDirectory.FullName, $"{testProject.Name}{Constants.ExeSuffix}"))
.WithEnvironmentVariable("DOTNET_ROOT", TestContext.Current.ToolsetUnderTest.DotNetRoot)
.Execute()
.Should()
.Pass();
}

[WindowsOnlyFact]
public void AppHost_contains_resources_from_the_managed_dll()
{
Expand Down
Loading