Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加dotnet6支持 #94

Closed
wants to merge 3 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<UseWPF>true</UseWPF>
<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Target Name="MoveThePublishFolderToLibFolder" AfterTargets="Publish">

<PropertyGroup>
<PublishFolderCleanerCommandArgs>dotnet "$(MSBuildThisFileDirectory)..\tools\net5.0\PublishFolderCleaner.dll" -p "$(PublishDir) " -a "$(AssemblyName)"</PublishFolderCleanerCommandArgs>
<PublishFolderCleanerCommandArgs>dotnet "$(MSBuildThisFileDirectory)..\tools\$(TargetFramework)\PublishFolderCleaner.dll" -p "$(PublishDir) " -a "$(AssemblyName)" -s $(PublishSingleFile)</PublishFolderCleanerCommandArgs>
</PropertyGroup>

<Exec Command="$(PublishFolderCleanerCommandArgs)"></Exec>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<!-- 发布应用用到 AppHost 不包括 .NET 45 等框架版本 -->
<TargetFrameworks>net5.0;netcoreapp3.1</TargetFrameworks>
<PackageId>dotnetCampus.PublishFolderCleaner</PackageId>
<IncludeBuildOutput>false</IncludeBuildOutput>
<DevelopmentToolPath>..\PublishFolderCleaner\bin\$(Configuration)\</DevelopmentToolPath>
<Description>本工具提供 NuGet 包,可以在安装完成之后,发布应用将让发布文件夹下只包含一个 exe 和一个 lib 文件夹。此 exe 即是入口可执行文件,而 lib 文件夹就是原本的发布文件夹下的其他的文件</Description>
</PropertyGroup>
<PropertyGroup>
<!-- 发布应用用到 AppHost 不包括 .NET 45 等框架版本 -->
<TargetFrameworks>net5.0;net6.0;net7.0</TargetFrameworks>
<PackageId>baozhangchi.PublishFolderCleaner</PackageId>
<IncludeBuildOutput>false</IncludeBuildOutput>
<DevelopmentToolPath>..\PublishFolderCleaner\bin\$(Configuration)\</DevelopmentToolPath>
<Description>本工具提供 NuGet 包,可以在安装完成之后,发布应用将让发布文件夹下只包含一个 exe 和一个 lib 文件夹。此 exe 即是入口可执行文件,而 lib 文件夹就是原本的发布文件夹下的其他的文件。此工具暂不支持单文件发布</Description>
<Version>0.0.2</Version>
<Authors>baozhangchi</Authors>
<Company>baozhangchi</Company>
<Copyright>Copyright © 2023 baozhangchi, All Rights Reserved.</Copyright>
<PackageProjectUrl>https://github.com/baozhangchi/dotnetcampus.DotNETBuildSDK</PackageProjectUrl>
<RepositoryUrl>https://github.com/baozhangchi/dotnetcampus.DotNETBuildSDK</RepositoryUrl>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net5.0' ">
<!-- 用于设置项目构建顺序 -->
<!-- 必须等待 PublishFolderCleaner 构建完成之后才能构建此项目 -->
<ProjectReference Include="..\PublishFolderCleaner\PublishFolderCleaner.csproj" ReferenceOutputAssembly="false" />
</ItemGroup>
<ItemGroup>
<!-- 用于设置项目构建顺序 -->
<!-- 必须等待 PublishFolderCleaner 构建完成之后才能构建此项目 -->
<ProjectReference Include="..\PublishFolderCleaner\PublishFolderCleaner.csproj" ReferenceOutputAssembly="false" />
</ItemGroup>

<Target Name="IncludeAllPublishFolderCleanerDependencies" BeforeTargets="_GetPackageFiles">
<ItemGroup>
<!-- 将 PublishFolderCleaner 的输出打包 -->
<None Include="$(DevelopmentToolPath)**" Pack="True" PackagePath="tools" />
<None Include="Assets\package.targets" Pack="True" PackagePath="\build\$(PackageId).targets" />
</ItemGroup>
</Target>
</Project>
<Target Name="IncludeAllPublishFolderCleanerDependencies" BeforeTargets="_GetPackageFiles">
<ItemGroup>
<!-- 将 PublishFolderCleaner 的输出打包 -->
<None Include="$(DevelopmentToolPath)**" Pack="True" PackagePath="tools" />
<None Include="Assets\package.targets" Pack="True" PackagePath="\build\$(PackageId).targets" />
</ItemGroup>
</Target>
</Project>
28 changes: 18 additions & 10 deletions PublishFolderCleaner/PublishFolderCleaner/Options.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
using dotnetCampus.Cli;
#region

namespace PublishFolderCleaner
using dotnetCampus.Cli;

#endregion

namespace PublishFolderCleaner;

public class Options
{
public class Options
{
[Option('p', "PublishFolder")]
public string PublishFolder { set; get; } = null!;

[Option('a', "ApplicationName")]
public string ApplicationName { set; get; } = null!;
}
#region Properties

[Option('p', "PublishFolder")] public string PublishFolder { set; get; } = null!;

[Option('a', "ApplicationName")] public string ApplicationName { set; get; } = null!;

[Option('s', "PublishSingleFile")]
public bool PublishSingleFile { get; set; } = false;

#endregion
}
47 changes: 27 additions & 20 deletions PublishFolderCleaner/PublishFolderCleaner/Program.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
using System;
#region

using System.IO;
using dotnetCampus.Cli;

namespace PublishFolderCleaner
#endregion

namespace PublishFolderCleaner;

internal class Program
{
class Program
{
static void Main(string[] args)
{
var options = CommandLine.Parse(args).As<Options>();
#region Methods

const string libFolderName = "lib";
var publishFolder = options.PublishFolder.Trim();
var libFolder = Path.GetFullPath(Path.Combine(publishFolder, libFolderName));
var tempFolder = Path.GetFullPath(Path.Combine(publishFolder, @"..", Path.GetRandomFileName()));
Directory.Move(publishFolder, tempFolder);
Directory.CreateDirectory(publishFolder);
Directory.Move(tempFolder, libFolder);
private static void Main(string[] args)
{
var options = CommandLine.Parse(args).As<Options>();
if (options.PublishSingleFile) return;
const string libFolderName = "lib";
var publishFolder = options.PublishFolder.Trim();
var libFolder = Path.GetFullPath(Path.Combine(publishFolder, libFolderName));
var tempFolder = Path.GetFullPath(Path.Combine(publishFolder, @"..", Path.GetRandomFileName()));
if (Directory.Exists(libFolder)) Directory.Delete(libFolder, true);
Directory.Move(publishFolder, tempFolder);
Directory.CreateDirectory(publishFolder);
Directory.Move(tempFolder, libFolder);

var appHostFilePath = Path.Combine(libFolder, options.ApplicationName + ".exe");
var newAppHostFilePath = Path.Combine(publishFolder, options.ApplicationName + ".exe");
var appHostFilePath = Path.Combine(libFolder, options.ApplicationName + ".exe");
var newAppHostFilePath = Path.Combine(publishFolder, options.ApplicationName + ".exe");

File.Move(appHostFilePath, newAppHostFilePath);
File.Move(appHostFilePath, newAppHostFilePath);

AppHostPatcher.Patch(newAppHostFilePath, Path.Combine("lib", options.ApplicationName + ".dll"));
}
AppHostPatcher.Patch(newAppHostFilePath, Path.Combine("lib", options.ApplicationName + ".dll"));
}
}

#endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFrameworks>net5.0;net5.0-windows;net6.0;net6.0-windows;net7.0;net7.0-windows</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down