Skip to content

Commit 0961cde

Browse files
committed
从启动配置
1 parent 12721a5 commit 0961cde

3 files changed

Lines changed: 116 additions & 54 deletions

File tree

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,37 @@
1-
<Project>
2-
<PropertyGroup>
3-
<!-- 我们使用 $(MSBuildRuntimeType) 来判断编译器是 .NET Core 的还是 .NET Framework 的。
4-
然后选用对应的文件夹。-->
5-
<NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder Condition=" '$(MSBuildRuntimeType)' == 'Core'">$(MSBuildThisFileDirectory)..\tools\netcoreapp2.2\</NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder>
6-
<NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder Condition=" '$(MSBuildRuntimeType)' != 'Core'">$(MSBuildThisFileDirectory)..\tools\net48\</NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder>
7-
</PropertyGroup>
8-
<UsingTask TaskName="UsingMSBuildCopyOutputFileToFastDebug.SafeOutputFileCopyTask"
9-
AssemblyFile="$(NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder)\UsingMSBuildCopyOutputFileToFastDebug.dll" />
10-
11-
<Target Name="CopyOutputLibToFastDebug" AfterTargets="AfterBuild"
12-
Condition="$(MainProjectPath)!=''">
13-
<Message Text="当前使用的复制方法 $(NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder)" />
14-
<ItemGroup>
15-
<OutputFileToCopy Include="$(OutputPath)$(AssemblyName).dll"></OutputFileToCopy>
16-
<OutputFileToCopy Include="$(OutputPath)$(AssemblyName).pdb"></OutputFileToCopy>
17-
</ItemGroup>
18-
<SafeOutputFileCopyTask SourceFiles="@(OutputFileToCopy)" DestinationFolder="$(MainProjectPath)"></SafeOutputFileCopyTask>
19-
</Target>
1+
<Project>
2+
<PropertyGroup>
3+
<!-- 我们使用 $(MSBuildRuntimeType) 来判断编译器是 .NET Core 的还是 .NET Framework 的。
4+
然后选用对应的文件夹。-->
5+
<NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder Condition=" '$(MSBuildRuntimeType)' == 'Core'">$(MSBuildThisFileDirectory)..\tools\netcoreapp2.2\</NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder>
6+
<NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder Condition=" '$(MSBuildRuntimeType)' != 'Core'">$(MSBuildThisFileDirectory)..\tools\net48\</NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder>
7+
</PropertyGroup>
8+
9+
10+
11+
<UsingTask TaskName="UsingMSBuildCopyOutputFileToFastDebug.SafeOutputFileCopyTask"
12+
AssemblyFile="$(NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder)\UsingMSBuildCopyOutputFileToFastDebug.dll" />
13+
<UsingTask TaskName="UsingMSBuildCopyOutputFileToFastDebug.LaunchSettingsParser"
14+
AssemblyFile="$(NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder)\UsingMSBuildCopyOutputFileToFastDebug.dll" />
15+
16+
<Target Name="ParseLaunchSettings" AfterTargets="AfterBuild">
17+
<Message Text="当前使用的复制方法 $(NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder)" />
18+
<LaunchSettingsParser>
19+
<Output TaskParameter="LaunchMainProjectPath" PropertyName="LaunchMainProjectPath" ></Output>
20+
</LaunchSettingsParser>
21+
</Target>
22+
23+
24+
<Target Name="CopyOutputLibToFastDebug" AfterTargets="AfterBuild"
25+
Condition="$(MainProjectPath)!='' or $(LaunchMainProjectPath)!=''">
26+
<Message Text="当前使用的复制方法 $(NuGetUsingMSBuildCopyOutputFileToFastDebugTaskFolder)" />
27+
<ItemGroup>
28+
<OutputFileToCopy Include="$(OutputPath)$(AssemblyName).dll"></OutputFileToCopy>
29+
<OutputFileToCopy Include="$(OutputPath)$(AssemblyName).pdb"></OutputFileToCopy>
30+
</ItemGroup>
31+
<SafeOutputFileCopyTask SourceFiles="@(OutputFileToCopy)" DestinationFolder="$(MainProjectPath)"
32+
Condition="$(MainProjectPath)!=''"></SafeOutputFileCopyTask>
33+
34+
<SafeOutputFileCopyTask SourceFiles="@(OutputFileToCopy)" DestinationFolder="$(LaunchMainProjectPath)"
35+
Condition="$(LaunchMainProjectPath)!='' and $(MainProjectPath)==''"></SafeOutputFileCopyTask>
36+
</Target>
2037
</Project>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.Globalization;
4+
using System.IO;
5+
using System.Runtime.Serialization.Json;
6+
using System.Xml;
7+
using Microsoft.Build.Framework;
8+
//using Newtonsoft.Json;
9+
//using Newtonsoft.Json.Linq;
10+
11+
namespace UsingMSBuildCopyOutputFileToFastDebug
12+
{
13+
public class LaunchSettingsParser : Microsoft.Build.Utilities.Task
14+
{
15+
/// <inheritdoc />
16+
public override bool Execute()
17+
{
18+
Debugger.Launch();
19+
20+
var file = Path.Combine("Properties", "launchSettings.json");
21+
Console.WriteLine("开始从 launchSettings 文件读取输出文件夹");
22+
Console.WriteLine($"开始读取{file}文件");
23+
if (!File.Exists(file))
24+
{
25+
Console.WriteLine($"找不到{file}文件,读取结束");
26+
}
27+
28+
var text = File.ReadAllText(file);
29+
30+
31+
//var jObject = JObject.Parse(File.ReadAllText(file));
32+
33+
return true;
34+
}
35+
36+
[Output]
37+
public string LaunchMainProjectPath { set; get; }
38+
}
39+
}
Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,42 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
2-
3-
<PropertyGroup>
4-
<OutputType>Library</OutputType>
5-
<TargetFrameworks>net48;netcoreapp2.2</TargetFrameworks>
6-
<Authors>dotnet-campus</Authors>
7-
<Product>dotnet-campus</Product>
8-
<PackageLicenseExpression>MIT</PackageLicenseExpression>
9-
<PackageProjectUrl>https://github.com/dotnet-campus/UsingMSBuildCopyOutputFileToFastDebug</PackageProjectUrl>
10-
<RepositoryUrl>https://github.com/dotnet-campus/UsingMSBuildCopyOutputFileToFastDebug</RepositoryUrl>
11-
<Description>
12-
Using MSBuild Copy Output File To Fast Debug
13-
通过复制输出文件让 VisualStudio 外部启动快速调试底层库
14-
</Description>
15-
<Copyright>Copyright (c) 2019 dotnet-campus</Copyright>
16-
<PackageTags>msbuild debug</PackageTags>
17-
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
18-
<BuildOutputTargetFolder>tools</BuildOutputTargetFolder>
19-
<NoPackageAnalysis>true</NoPackageAnalysis>
20-
<ApplicationIcon />
21-
<StartupObject />
22-
<Version>1.3.1</Version>
23-
<PackageId>dotnetCampus.UsingMSBuildCopyOutputFileToFastDebug</PackageId>
24-
</PropertyGroup>
25-
26-
<ItemGroup>
27-
<PackageReference Include="Microsoft.Build.Framework" Version="16.0.461" />
28-
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="16.0.461" />
29-
<PackageReference Update="@(PackageReference)" PrivateAssets="All" />
30-
</ItemGroup>
31-
32-
<ItemGroup>
33-
<None Include="build\dotnetCampus.UsingMSBuildCopyOutputFileToFastDebug.targets" Pack="True" PackagePath="\build"/>
34-
<None Include="buildMultiTargeting\dotnetCampus.UsingMSBuildCopyOutputFileToFastDebug.targets" Pack="True" PackagePath="\buildMultiTargeting"/>
35-
</ItemGroup>
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Library</OutputType>
5+
<TargetFrameworks>net48;netcoreapp2.2</TargetFrameworks>
6+
<Authors>dotnet-campus</Authors>
7+
<Product>dotnet-campus</Product>
8+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
9+
<PackageProjectUrl>https://github.com/dotnet-campus/UsingMSBuildCopyOutputFileToFastDebug</PackageProjectUrl>
10+
<RepositoryUrl>https://github.com/dotnet-campus/UsingMSBuildCopyOutputFileToFastDebug</RepositoryUrl>
11+
<Description>
12+
Using MSBuild Copy Output File To Fast Debug
13+
通过复制输出文件让 VisualStudio 外部启动快速调试底层库
14+
</Description>
15+
<Copyright>Copyright (c) 2019 dotnet-campus</Copyright>
16+
<PackageTags>msbuild debug</PackageTags>
17+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
18+
<BuildOutputTargetFolder>tools</BuildOutputTargetFolder>
19+
<NoPackageAnalysis>true</NoPackageAnalysis>
20+
<ApplicationIcon />
21+
<StartupObject />
22+
<Version>1.3.7</Version>
23+
<PackageId>dotnetCampus.UsingMSBuildCopyOutputFileToFastDebug</PackageId>
24+
</PropertyGroup>
25+
26+
<ItemGroup>
27+
<PackageReference Include="Microsoft.Build.Framework" Version="16.0.461" />
28+
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="16.0.461" />
29+
<!--<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />-->
30+
<PackageReference Update="@(PackageReference)" PrivateAssets="All" />
31+
</ItemGroup>
32+
33+
<Target Name="UsingMSBuildCopyOutputFileToFastDebugPackage" BeforeTargets="_GetPackageFiles">
34+
<ItemGroup>
35+
<!--<None Include="$(OutputPath)\net48\Newtonsoft.Json.dll" Pack="True" PackagePath="\tools\net48\Newtonsoft.Json.dll" />
36+
<None Include="$(USERPROFILE)\.nuget\packages\Newtonsoft.Json\12.0.2\lib\netstandard2.0\Newtonsoft.Json.dll" Pack="True" PackagePath="\tools\netcoreapp2.2\Newtonsoft.Json.dll" />-->
37+
<None Include="build\dotnetCampus.UsingMSBuildCopyOutputFileToFastDebug.targets" Pack="True" PackagePath="\build\$(PackageId).targets" />
38+
<None Include="buildMultiTargeting\dotnetCampus.UsingMSBuildCopyOutputFileToFastDebug.targets" Pack="True" PackagePath="\buildMultiTargeting" />
39+
</ItemGroup>
40+
</Target>
41+
3642
</Project>

0 commit comments

Comments
 (0)