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
6 changes: 6 additions & 0 deletions src/Layout/redist/dnx.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# dnx.ps1
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't use PowerShell much and I just generated this script by asking copilot to translate the batch script to PowerShell. So I'd appreciate review of the script from someone more familiar with PowerShell.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a #Requires -Version 6.0
to make sure powershell supports Split-Path?

@Args was also added in 3.0 (2012 powershell).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like Split-Path has been around since PowerShell 1.0. We don't want to require version 6 of PowerShell, I think that's the .NET Core version that you have to install separately. I think we want this script to work on the PowerShell that's included with Windows. As far as I can tell it does. The lowest version of Windows we support is Server 2012 which has PowerShell 3, so I think we're good.

# PowerShell script to launch dotnet.exe with 'dnx' and all passed arguments
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Users will need to select the ps1 script instead of the cmd, right? Is it ok that DnxShimSource can contain 2 possible shim sources now, and is there any logic that might need updating because of this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're running PowerShell, then the ps1 script will take precedence over the .cmd script. So either way you just type dnx, and from PowerShell you'll get the ps1 script with improved CTRL+C handling, and from a cmd shell you'll get the .cmd script and the extra CTRL+C termination confirmation.

The only use of DnxShimSource is in GenerateInstallerLayout.targets and it has been updated to handle the items appropriately.

$dotnet = Join-Path $scriptDir 'dotnet.exe'
& $dotnet dnx @Args
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the path contains a space, I think this might not work. But there is a different process for running an executable via a string, which I don't remember off the top of my head. That stuff can get pretty annoying in PowerShell.

exit $LASTEXITCODE
17 changes: 9 additions & 8 deletions src/Layout/redist/targets/GenerateInstallerLayout.targets
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,13 @@
Overwrite="true" />
</Target>

<Target Name="LayoutDnxScript">
<PropertyGroup>
<DnxScriptSource Condition="$([MSBuild]::IsOSPlatform('WINDOWS'))">dnx.cmd</DnxScriptSource>
<DnxScriptSource Condition="!$([MSBuild]::IsOSPlatform('WINDOWS'))">dnx</DnxScriptSource>
</PropertyGroup>
<Copy SourceFiles="$(DnxScriptSource)" DestinationFolder="$(RedistInstallerLayoutPath)" />
<Target Name="LayoutDnxShim">
<ItemGroup>
<DnxShimSource Condition="$([MSBuild]::IsOSPlatform('Windows'))" Include="dnx.cmd" />
<DnxShimSource Condition="$([MSBuild]::IsOSPlatform('Windows'))" Include="dnx.ps1" />
<DnxShimSource Condition="!$([MSBuild]::IsOSPlatform('WINDOWS'))" Include="dnx" />
</ItemGroup>
<Copy SourceFiles="@(DnxShimSource)" DestinationFolder="$(RedistInstallerLayoutPath)" />

<!-- Mark script as executable -->
<Exec Command="chmod 755 &quot;$(RedistInstallerLayoutPath)/dnx&quot;" Condition="!$([MSBuild]::IsOSPlatform('Windows'))" />
Expand All @@ -92,7 +93,7 @@
LayoutManifests;
LayoutBaselineWorkloadSet;
LayoutWorkloadUserLocalMarker;
LayoutDnxScript;
LayoutDnxShim;
CrossgenLayout;
ReplaceBundledRuntimePackFilesWithSymbolicLinks"
AfterTargets="AfterBuild" />
Expand All @@ -115,7 +116,7 @@
SkipUnchangedFiles="true" />

<!-- Copy dnx script to root dotnet folder (which will map to DOTNETHOME) -->
<Copy SourceFiles="dnx.cmd" DestinationFolder="$(IntermediateSdkInstallerOutputPath)" />
<Copy SourceFiles="@(DnxShimSource)" DestinationFolder="$(IntermediateSdkInstallerOutputPath)" />

</Target>

Expand Down
Loading