diff --git a/Code/ToolPackager/Build/dotnetCampus.UsingMSBuildCopyOutputFileToFastDebug.targets b/Code/ToolPackager/Build/dotnetCampus.UsingMSBuildCopyOutputFileToFastDebug.targets index 5f656e4..2a2ac44 100644 --- a/Code/ToolPackager/Build/dotnetCampus.UsingMSBuildCopyOutputFileToFastDebug.targets +++ b/Code/ToolPackager/Build/dotnetCampus.UsingMSBuildCopyOutputFileToFastDebug.targets @@ -30,7 +30,7 @@ + Command="dotnet $(UsingMSBuildCopyOutputFileToFastDebugTaskFile) -- CopyOutputFile $(MainProjectExecutablePathCommandArgs) -CleanFilePath $(CleanUsingMSBuildCopyOutputFileToFastDebugFile) -OutputFileToCopyList $(OutputFileToCopyList) -TargetFramework $(TargetFramework) -TargetFrameworks $(TargetFrameworks)" /> - - - net5.0;net45;netstandard1.0 - - - - - dotnetCampus.UsingMSBuildCopyOutputFileToFastDebug - - - true - - false - - - true - - - - - - - - - - - ..\UsingMSBuildCopyOutputFileToFastDebug\bin\Debug\net5.0\ - - ..\UsingMSBuildCopyOutputFileToFastDebug\bin\Release\net5.0\ - - - - - - - + + + + net5.0;net45;netstandard1.0;net6.0;net7.0;net8.0;net9.0 + + + + + dotnetCampus.UsingMSBuildCopyOutputFileToFastDebug + + + true + + false + + + true + + + + + + + + + + + ..\UsingMSBuildCopyOutputFileToFastDebug\bin\Debug\net5.0\ + + ..\UsingMSBuildCopyOutputFileToFastDebug\bin\Release\net5.0\ + + + + + + + - + diff --git a/Code/UsingMSBuildCopyOutputFileToFastDebug/Program.cs b/Code/UsingMSBuildCopyOutputFileToFastDebug/Program.cs index eb6fdf3..97d5aa9 100644 --- a/Code/UsingMSBuildCopyOutputFileToFastDebug/Program.cs +++ b/Code/UsingMSBuildCopyOutputFileToFastDebug/Program.cs @@ -98,7 +98,11 @@ private static void CopyOutputFile(CopyOutputFileOptions copyOutputFileOptions) Logger.Message($"LaunchMainProjectExecutablePath={launchMainProjectExecutableFile}"); var destinationFolder = launchMainProjectExecutableFile.Directory; - if (TargetFrameworkChecker.CheckCanCopy(launchMainProjectExecutableFile, copyOutputFileOptions) is false) + + var isSingleFramework = IsSingleFramework(copyOutputFileOptions); + + // 非单个框架,即多个框架的情况下,需要检查是否可以拷贝 + if (!isSingleFramework && TargetFrameworkChecker.CheckCanCopy(launchMainProjectExecutableFile, copyOutputFileOptions) is false) { #if DEBUG Logger.Message($"当前框架{copyOutputFileOptions.TargetFramework}与{launchMainProjectExecutableFile.FullName}不兼容"); @@ -117,6 +121,21 @@ private static void CopyOutputFile(CopyOutputFileOptions copyOutputFileOptions) safeOutputFileCopyTask.Execute(); } + private static bool IsSingleFramework(CopyOutputFileOptions copyOutputFileOptions) + { + var targetFrameworks = copyOutputFileOptions.TargetFrameworks; + if (string.IsNullOrEmpty(targetFrameworks)) + { + // 没有记录 TargetFrameworks 属性,则证明是单个框架 + // 如 net9.0 + return true; + } + + // 虽然写的是 TargetFrameworks 属性,但是实际上是单个框架 + // 如 net9.0 + return targetFrameworks == copyOutputFileOptions.TargetFramework; + } + /// /// 获取准备运行的 Exe 的路径 /// @@ -189,6 +208,9 @@ public class CopyOutputFileOptions [Option("TargetFramework")] public string TargetFramework { set; get; } = null!; + [Option("TargetFrameworks")] + public string? TargetFrameworks { set; get; } + public List GetOutputFileList() { var fileList = new List(); diff --git a/Code/UsingMSBuildCopyOutputFileToFastDebug/TargetFrameworkChecker.cs b/Code/UsingMSBuildCopyOutputFileToFastDebug/TargetFrameworkChecker.cs index df1d1ca..2a71794 100644 --- a/Code/UsingMSBuildCopyOutputFileToFastDebug/TargetFrameworkChecker.cs +++ b/Code/UsingMSBuildCopyOutputFileToFastDebug/TargetFrameworkChecker.cs @@ -155,7 +155,27 @@ private static DotNetType GetTargetFrameworkDotNetType(string targetFramework) return DotNetType.Net6; } - throw new ArgumentException($"Unknown TargetFrame {targetFramework}"); + if (targetFramework.Contains("net7.")) + { + return DotNetType.Net7; + } + + if (targetFramework.Contains("net8.")) + { + return DotNetType.Net8; + } + + if (targetFramework.Contains("net9.")) + { + return DotNetType.Net9; + } + + if (Regex.IsMatch(targetFramework, @"net\d")) + { + return DotNetType.NetCore; + } + + throw new ArgumentException($"Unknown TargetFramework {targetFramework}"); } } @@ -183,5 +203,8 @@ public enum DotNetType Net5 = 1 << 15 | NetCore, Net6 = 1 << 16 | NetCore, + Net7 = 1 << 17 | NetCore, + Net8 = 1 << 18 | NetCore, + Net9 = 1 << 19 | NetCore, } } \ No newline at end of file diff --git a/Directory.Build.props b/Directory.Build.props index 52374af..942e4e5 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -8,7 +8,7 @@ https://github.com/dotnet-campus/UsingMSBuildCopyOutputFileToFastDebug https://github.com/dotnet-campus/UsingMSBuildCopyOutputFileToFastDebug Using MSBuild Copy Output File To Fast Debug. 通过复制输出文件让 VisualStudio 外部启动快速调试底层库 - Copyright (c) 2019-2021 dotnet-campus + Copyright (c) 2019-$([System.DateTime]::Now.ToString(`yyyy`)) dotnet-campus msbuild debug true tools