Skip to content

Commit

Permalink
解决多个框架打包引用文件
Browse files Browse the repository at this point in the history
多个框架都会触发打包,打包会写文件,多个框架并行写文件提示文件占用。通过判断多个开发框架不进行打包,只有一个打包应用在多框架写文件

#57
  • Loading branch information
lindexi committed Jan 1, 2020
1 parent 5a62e3a commit 8e8f8cd
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 109 deletions.
2 changes: 1 addition & 1 deletion build/Version.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<Version>0.1.19002-alpha</Version>
<Version>0.1.19003-alpha</Version>
</PropertyGroup>
</Project>
114 changes: 114 additions & 0 deletions src/dotnetCampus.SourceYard/Assets/Current/SourceYard.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<Project>

<!-- 打包核心 -->

<!-- 避免依赖传递。 -->
<Target Name="_SourceYardPrivateAssets"
BeforeTargets="CollectPackageReferences">
<ItemGroup>
<PackageReference Update="dotnetCampus.SourceYard" PrivateAssets="all" />
</ItemGroup>
<Message Text="避免 SourceYard 依赖传递导致目标项目也打出源代码包" />
</Target>

<Target Name="SourceYard" >
<PropertyGroup>
<SourcePackingDirectory>$(IntermediateOutputPath)SourcePacking\</SourcePackingDirectory>

<CompileTextFile>$(SourcePackingDirectory)CompileFile.txt</CompileTextFile>
<ResourceTextFile>$(SourcePackingDirectory)ResourceFile.txt</ResourceTextFile>
<ContentTextFile>$(SourcePackingDirectory)ContentFile.txt</ContentTextFile>
<NoneTextFile>$(SourcePackingDirectory)NoneFile.txt</NoneTextFile>
<EmbeddedResourceTextFile>$(SourcePackingDirectory)EmbeddedResourceFile.txt</EmbeddedResourceTextFile>
<PageTextFile>$(SourcePackingDirectory)PageFile.txt</PageTextFile>
<ApplicationDefinitionTextFile>$(SourcePackingDirectory)ApplicationDefinitionFile.txt</ApplicationDefinitionTextFile>

<DescriptionFile>$(SourcePackingDirectory)DescriptionFile.txt</DescriptionFile>
<CopyrightFile>$(SourcePackingDirectory)CopyrightFile.txt</CopyrightFile>
<PackageReleaseNotesFile>$(SourcePackingDirectory)PackageReleaseNotesFile.txt</PackageReleaseNotesFile>

<PackageReferenceVersionFile>$(SourcePackingDirectory)PackageReferenceVersionFile.txt</PackageReferenceVersionFile>
<SourceProjectPackageFile>$(SourcePackingDirectory)SourceProjectPackageFile.txt</SourceProjectPackageFile>
</PropertyGroup>

<MakeDir Condition="!Exists($(SourcePackingDirectory))" Directories="$(SourcePackingDirectory)"></MakeDir>

<WriteLinesToFile File="$(CompileTextFile)" Lines="@(Compile)" Overwrite="true" />
<WriteLinesToFile File="$(ResourceTextFile)" Lines="@(Resource)" Overwrite="true" />
<WriteLinesToFile File="$(ContentTextFile)" Lines="@(Content)" Overwrite="true" />
<WriteLinesToFile File="$(NoneTextFile)" Lines="@(None)" Overwrite="true" />
<WriteLinesToFile File="$(EmbeddedResourceTextFile)" Lines="@(EmbeddedResource)" Overwrite="true" />
<WriteLinesToFile File="$(PageTextFile)" Lines="@(Page)" Overwrite="true" />
<WriteLinesToFile File="$(ApplicationDefinitionTextFile)" Lines="@(ApplicationDefinition)" Overwrite="true" />

<WriteLinesToFile File="$(DescriptionFile)" Lines="$(Description)" Overwrite="true"></WriteLinesToFile>
<WriteLinesToFile File="$(CopyrightFile)" Lines="$(Copyright)" Overwrite="true"></WriteLinesToFile>
<WriteLinesToFile File="$(PackageReleaseNotesFile)" Lines="$(PackageReleaseNotes)" Overwrite="true"></WriteLinesToFile>

<!-- 写入通用的信息 -->
<!-- 多段写入之前需要先删除文件 -->
<Delete Files="$(SourceProjectPackageFile)" Condition="Exists($(SourceProjectPackageFile))"></Delete>
<!-- 先写入RepositoryType的值,解析时将会根据此值顺序解析 -->
<WriteLinesToFile File="$(SourceProjectPackageFile)" Lines=">;RepositoryType;$(RepositoryType);"></WriteLinesToFile>
<WriteLinesToFile File="$(SourceProjectPackageFile)" Lines=">;PackageProjectUrl;$(PackageProjectUrl);"></WriteLinesToFile>
<WriteLinesToFile File="$(SourceProjectPackageFile)" Lines=">;RepositoryUrl;$(RepositoryUrl);"></WriteLinesToFile>

<ItemGroup>
<_PackageReferenceVersion
Include="Name='%(PackageReference.Identity)' Version='%(PackageReference.Version)' PrivateAssets='%(PackageReference.PrivateAssets)'">
</_PackageReferenceVersion>
</ItemGroup>
<WriteLinesToFile File="$(PackageReferenceVersionFile)" Lines="@(_PackageReferenceVersion)" Overwrite="true" />

<PropertyGroup>

<SourceYardAuthors Condition="$(Authors) != ''">--Authors "$(Authors)"</SourceYardAuthors>

<!-- 这部分长度太长会让命令行无法输入
<SourceYardRepositoryUrl Condition="$(RepositoryUrl) != ''">RepositoryUrl "$(RepositoryUrl)"</SourceYardRepositoryUrl>
<SourceYardRepositoryType Condition="$(RepositoryType) != ''">RepositoryType "$(RepositoryType)"</SourceYardRepositoryType>
<SourceYardPackageProjectUrl Condition="$(PackageProjectUrl) != ''">PackageProjectUrl "$(PackageProjectUrl)"</SourceYardPackageProjectUrl>-->
<SourceYardPackageLicenseUrl Condition="$(PackageLicenseUrl) != ''">--PackageLicenseUrl "$(PackageLicenseUrl) "</SourceYardPackageLicenseUrl>

<SourceYardCopyright Condition="$(Copyright) != ''">--CopyrightFile "$(CopyrightFile)"</SourceYardCopyright>

<SourceYardPackageVersion Condition="$(PackageVersion) != ''">-v $(PackageVersion)</SourceYardPackageVersion>

<SourceYardDescription Condition="$(Description) != ''">--DescriptionFile "$(DescriptionFile) "</SourceYardDescription>

<SourceYardTitle Condition="$(Title) != ''">--Title "$(Title)"</SourceYardTitle>
<SourceYardOwner Condition="$(Owner) != ''">--Owner "$(Owner)"</SourceYardOwner>
<SourceYardPackageTags Condition="$(PackageTags) != ''">--PackageTags "$(PackageTags) "</SourceYardPackageTags>
<SourceYardPackageReleaseNotes Condition="$(PackageReleaseNotes) != ''"> --PackageReleaseNotesFile $(PackageReleaseNotesFile)</SourceYardPackageReleaseNotes>
<SourceYardPackageId Condition="'$(PackageId)' != ''">--PackageId "$(PackageId) "</SourceYardPackageId>

<SourceMSBuildProjectFullPath>-p "$(MSBuildProjectFullPath) "</SourceMSBuildProjectFullPath>
<SourceIntermediateDirectory>-i "$(SourcePackingDirectory)Package "</SourceIntermediateDirectory>
<SourcePackageOutputPath Condition="'$(PackageOutputPath)' != ''">-n "$(PackageOutputPath) "</SourcePackageOutputPath>
<SourcePackageOutputPath Condition="'$(PackageOutputPath)' == '' and $(OutputPath) != ''">-n "$(OutputPath) "</SourcePackageOutputPath>
<SourcePackageReferenceVersion>--PackageReferenceVersion "$(PackageReferenceVersionFile)"</SourcePackageReferenceVersion>

</PropertyGroup>


<Exec
Command="$(MSBuildThisFileDirectory)..\tools\net45\dotnetCampus.SourceYard.exe $(SourceMSBuildProjectFullPath) $(SourceIntermediateDirectory) $(SourcePackageOutputPath) $(SourceYardPackageVersion) --Compile $(CompileTextFile) --Resource $(ResourceTextFile) --Content $(ContentTextFile) --Page $(PageTextFile) --ApplicationDefinition $(ApplicationDefinitionTextFile) --None $(NoneTextFile) --EmbeddedResource $(EmbeddedResourceTextFile) $(SourceYardAuthors) $(SourceYardRepositoryUrl) $(SourceYardRepositoryType) $(SourceYardPackageProjectUrl) $(SourceYardCopyright) $(SourceYardDescription) $(SourceYardTitle) $(SourceYardPackageLicenseUrl) $(SourceYardPackageReleaseNotes) $(SourceYardPackageTags) $(SourceYardOwner) $(SourceYardPackageId) $(SourcePackageReferenceVersion) --SourcePackingDirectory $(SourcePackingDirectory)">
</Exec>
</Target>

<PropertyGroup>
<CleanDependsOn>$(CleanDependsOn);_SourceYardClean</CleanDependsOn>
</PropertyGroup>

<Target Name="_SourceYardClean">
<PropertyGroup>
<_SourcePackingDirectory>$(IntermediateOutputPath)SourcePacking\</_SourcePackingDirectory>
</PropertyGroup>
<RemoveDir Directories="$(_SourcePackingDirectory)" />
</Target>

<Target Name="SourceYardFalsePackSource" AfterTargets="Build"
Condition="$(PackSource) == 'False'">
<Message Text="因为用户设置 PackSource 为 false 所以没有打包源代码"></Message>
</Target>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project>

<Import Project="..\build\SourceYard.targets"/>

<Target Name="BuildSourceNuGet" AfterTargets="Build"
DependsOnTargets="SourceYard"
Condition="$(PackSource) != 'False'">

</Target>
</Project>
Original file line number Diff line number Diff line change
@@ -1,113 +1,11 @@
<Project>

<!-- 避免依赖传递。 -->
<Target Name="_SourceYardPrivateAssets"
BeforeTargets="CollectPackageReferences">
<ItemGroup>
<PackageReference Update="dotnetCampus.SourceYard" PrivateAssets="all" />
</ItemGroup>
<Message Text="避免 SourceYard 依赖传递导致目标项目也打出源代码包" />
</Target>

<Target Name="SourceYard" AfterTargets="GenerateNuspec"
Condition="$(PackSource) != 'False'">
<PropertyGroup>
<SourcePackingDirectory>$(IntermediateOutputPath)SourcePacking\</SourcePackingDirectory>

<CompileTextFile>$(SourcePackingDirectory)CompileFile.txt</CompileTextFile>
<ResourceTextFile>$(SourcePackingDirectory)ResourceFile.txt</ResourceTextFile>
<ContentTextFile>$(SourcePackingDirectory)ContentFile.txt</ContentTextFile>
<NoneTextFile>$(SourcePackingDirectory)NoneFile.txt</NoneTextFile>
<EmbeddedResourceTextFile>$(SourcePackingDirectory)EmbeddedResourceFile.txt</EmbeddedResourceTextFile>
<PageTextFile>$(SourcePackingDirectory)PageFile.txt</PageTextFile>
<ApplicationDefinitionTextFile>$(SourcePackingDirectory)ApplicationDefinitionFile.txt</ApplicationDefinitionTextFile>

<DescriptionFile>$(SourcePackingDirectory)DescriptionFile.txt</DescriptionFile>
<CopyrightFile>$(SourcePackingDirectory)CopyrightFile.txt</CopyrightFile>
<PackageReleaseNotesFile>$(SourcePackingDirectory)PackageReleaseNotesFile.txt</PackageReleaseNotesFile>

<PackageReferenceVersionFile>$(SourcePackingDirectory)PackageReferenceVersionFile.txt</PackageReferenceVersionFile>
<SourceProjectPackageFile>$(SourcePackingDirectory)SourceProjectPackageFile.txt</SourceProjectPackageFile>
</PropertyGroup>

<MakeDir Condition="!Exists($(SourcePackingDirectory))" Directories="$(SourcePackingDirectory)"></MakeDir>

<WriteLinesToFile File="$(CompileTextFile)" Lines="@(Compile)" Overwrite="true" />
<WriteLinesToFile File="$(ResourceTextFile)" Lines="@(Resource)" Overwrite="true" />
<WriteLinesToFile File="$(ContentTextFile)" Lines="@(Content)" Overwrite="true" />
<WriteLinesToFile File="$(NoneTextFile)" Lines="@(None)" Overwrite="true" />
<WriteLinesToFile File="$(EmbeddedResourceTextFile)" Lines="@(EmbeddedResource)" Overwrite="true" />
<WriteLinesToFile File="$(PageTextFile)" Lines="@(Page)" Overwrite="true" />
<WriteLinesToFile File="$(ApplicationDefinitionTextFile)" Lines="@(ApplicationDefinition)" Overwrite="true" />

<WriteLinesToFile File="$(DescriptionFile)" Lines="$(Description)" Overwrite="true"></WriteLinesToFile>
<WriteLinesToFile File="$(CopyrightFile)" Lines="$(Copyright)" Overwrite="true"></WriteLinesToFile>
<WriteLinesToFile File="$(PackageReleaseNotesFile)" Lines="$(PackageReleaseNotes)" Overwrite="true"></WriteLinesToFile>

<!-- 写入通用的信息 -->
<!-- 多段写入之前需要先删除文件 -->
<Delete Files="$(SourceProjectPackageFile)" Condition="Exists($(SourceProjectPackageFile))"></Delete>
<!-- 先写入RepositoryType的值,解析时将会根据此值顺序解析 -->
<WriteLinesToFile File="$(SourceProjectPackageFile)" Lines=">;RepositoryType;$(RepositoryType);"></WriteLinesToFile>
<WriteLinesToFile File="$(SourceProjectPackageFile)" Lines=">;PackageProjectUrl;$(PackageProjectUrl);"></WriteLinesToFile>
<WriteLinesToFile File="$(SourceProjectPackageFile)" Lines=">;RepositoryUrl;$(RepositoryUrl);"></WriteLinesToFile>

<ItemGroup>
<_PackageReferenceVersion
Include="Name='%(PackageReference.Identity)' Version='%(PackageReference.Version)' PrivateAssets='%(PackageReference.PrivateAssets)'">
</_PackageReferenceVersion>
</ItemGroup>
<WriteLinesToFile File="$(PackageReferenceVersionFile)" Lines="@(_PackageReferenceVersion)" Overwrite="true" />

<PropertyGroup>

<SourceYardAuthors Condition="$(Authors) != ''">--Authors "$(Authors)"</SourceYardAuthors>

<!-- 这部分长度太长会让命令行无法输入
<SourceYardRepositoryUrl Condition="$(RepositoryUrl) != ''">RepositoryUrl "$(RepositoryUrl)"</SourceYardRepositoryUrl>
<SourceYardRepositoryType Condition="$(RepositoryType) != ''">RepositoryType "$(RepositoryType)"</SourceYardRepositoryType>
<SourceYardPackageProjectUrl Condition="$(PackageProjectUrl) != ''">PackageProjectUrl "$(PackageProjectUrl)"</SourceYardPackageProjectUrl>-->
<SourceYardPackageLicenseUrl Condition="$(PackageLicenseUrl) != ''">--PackageLicenseUrl "$(PackageLicenseUrl) "</SourceYardPackageLicenseUrl>
<Import Project="SourceYard.targets"/>

<SourceYardCopyright Condition="$(Copyright) != ''">--CopyrightFile "$(CopyrightFile)"</SourceYardCopyright>
<Target Name="BuildSourceNuGet" AfterTargets="Build"
DependsOnTargets="SourceYard"
Condition="$(PackSource) != 'False' And '$(TargetFrameworks)' == ''">

<SourceYardPackageVersion Condition="$(PackageVersion) != ''">-v $(PackageVersion)</SourceYardPackageVersion>

<SourceYardDescription Condition="$(Description) != ''">--DescriptionFile "$(DescriptionFile) "</SourceYardDescription>

<SourceYardTitle Condition="$(Title) != ''">--Title "$(Title)"</SourceYardTitle>
<SourceYardOwner Condition="$(Owner) != ''">--Owner "$(Owner)"</SourceYardOwner>
<SourceYardPackageTags Condition="$(PackageTags) != ''">--PackageTags "$(PackageTags) "</SourceYardPackageTags>
<SourceYardPackageReleaseNotes Condition="$(PackageReleaseNotes) != ''"> --PackageReleaseNotesFile $(PackageReleaseNotesFile)</SourceYardPackageReleaseNotes>
<SourceYardPackageId Condition="'$(PackageId)' != ''">--PackageId "$(PackageId) "</SourceYardPackageId>

<SourceMSBuildProjectFullPath>-p "$(MSBuildProjectFullPath) "</SourceMSBuildProjectFullPath>
<SourceIntermediateDirectory>-i "$(SourcePackingDirectory)Package "</SourceIntermediateDirectory>
<SourcePackageOutputPath Condition="'$(PackageOutputPath)' != ''">-n "$(PackageOutputPath) "</SourcePackageOutputPath>
<SourcePackageOutputPath Condition="'$(PackageOutputPath)' == '' and $(OutputPath) != ''">-n "$(OutputPath) "</SourcePackageOutputPath>
<SourcePackageReferenceVersion>--PackageReferenceVersion "$(PackageReferenceVersionFile)"</SourcePackageReferenceVersion>

</PropertyGroup>


<Exec
Command="$(MSBuildThisFileDirectory)..\tools\net45\dotnetCampus.SourceYard.exe $(SourceMSBuildProjectFullPath) $(SourceIntermediateDirectory) $(SourcePackageOutputPath) $(SourceYardPackageVersion) --Compile $(CompileTextFile) --Resource $(ResourceTextFile) --Content $(ContentTextFile) --Page $(PageTextFile) --ApplicationDefinition $(ApplicationDefinitionTextFile) --None $(NoneTextFile) --EmbeddedResource $(EmbeddedResourceTextFile) $(SourceYardAuthors) $(SourceYardRepositoryUrl) $(SourceYardRepositoryType) $(SourceYardPackageProjectUrl) $(SourceYardCopyright) $(SourceYardDescription) $(SourceYardTitle) $(SourceYardPackageLicenseUrl) $(SourceYardPackageReleaseNotes) $(SourceYardPackageTags) $(SourceYardOwner) $(SourceYardPackageId) $(SourcePackageReferenceVersion) --SourcePackingDirectory $(SourcePackingDirectory)">
</Exec>
</Target>

<PropertyGroup>
<CleanDependsOn>$(CleanDependsOn);_SourceYardClean</CleanDependsOn>
</PropertyGroup>

<Target Name="_SourceYardClean">
<PropertyGroup>
<_SourcePackingDirectory>$(IntermediateOutputPath)SourcePacking\</_SourcePackingDirectory>
</PropertyGroup>
<RemoveDir Directories="$(_SourcePackingDirectory)" />
</Target>

<Target Name="SourceYardFalsePackSource" AfterTargets="Build"
Condition="$(PackSource) == 'False'">
<Message Text="因为用户设置 PackSource 为 false 所以没有打包源代码"></Message>
</Target>
</Project>
</Project>
7 changes: 6 additions & 1 deletion src/dotnetCampus.SourceYard/dotnetCampus.SourceYard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@

<ItemGroup>
<!--指定自己的在安装 nuget 时修改编译-->
<None Include="Assets\Current\**" Pack="True" PackagePath="build\" />
<None Include="Assets\Current\dotnetCampus.SourceYard.props" Pack="True" PackagePath="build\dotnetCampus.SourceYard.props" />
<None Include="Assets\Current\dotnetCampus.SourceYard.targets" Pack="True" PackagePath="build\dotnetCampus.SourceYard.targets" />
<None Include="Assets\Current\SourceYard.targets" Pack="True" PackagePath="build\SourceYard.targets" />

<None Include="Assets\Current\dotnetCampus.SourceYard.props" Pack="True" PackagePath="buildMultiTargeting\dotnetCampus.SourceYard.props" />
<None Include="Assets\Current\dotnetCampus.SourceYard.BuildMultiTargeting.targets" Pack="True" PackagePath="buildMultiTargeting\dotnetCampus.SourceYard.targets" />
<None Include="Assets\README.md" Pack="True" PackagePath="" />
<None Include="$(OutputPath)**\**" Pack="True" PackagePath="tools\" Visible="false" />
</ItemGroup>
Expand Down

0 comments on commit 8e8f8cd

Please sign in to comment.