Skip to content

Commit

Permalink
* 新增Fea,为C++添加 contentFiles 特性支持。
Browse files Browse the repository at this point in the history
  • Loading branch information
mingkuang-Chuyu committed Sep 16, 2020
1 parent 767edef commit 6a9d05c
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
################################################################################
# 此 .gitignore 文件已由 Microsoft(R) Visual Studio 自动创建。
################################################################################

/.vs
*.nupkg
37 changes: 37 additions & 0 deletions YY.NuGet.Import.Helper.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/01/nuspec.xsd">
<metadata minClientVersion="2.5">
<id>YY.NuGet.Import.Helper</id>
<title>NuGet属性表导入助手</title>
<version>$version$</version>
<summary>用于增强NuGet属性表导入。</summary>
<authors>YY</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<license type="expression">MIT</license>
<projectUrl>https://github.com/mingkuang-Chuyu/YY.NuGet.Import.Helper</projectUrl>
<description>功能 —— 增强NuGet导入

该 Helper 新增了 4 组导入位点,分别是:

$(VCTargetsPath)\Microsoft.Cpp.props 之前
$(VCTargetsPath)\Microsoft.Cpp.props 之后
$(VCTargetsPath)\Microsoft.Cpp.targets 之前
$(VCTargetsPath)\Microsoft.Cpp.targets 之后

全面增强C++ Import,让你的NuGet包创造更多可能!

</description>
<releaseNotes>
* 新增Fea,为C++添加 contentFiles 特性支持。
</releaseNotes>
<copyright>Copyright © 2020 YY</copyright>
<tags>YY Import Import.Helper native nativepackage</tags>
<repository type="git" url="https://github.com/mingkuang-Chuyu/YY.NuGet.Import.Helper.git" branch="master" commit="$commit$" />
</metadata>
<files>
<file src=".\*.props" target="build\native" />
<file src=".\*.targets" target="build\native" />
<file src=".\Fallback\**" target="build\native\Fallback" />
<file src=".\Thunks\**" target="build\native\Thunks" />
</files>
</package>
2 changes: 1 addition & 1 deletion YY.NuGet.Import.Helper.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ $(VisualStudioVersion)

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<NuGetImportHelperVersion>1.0.0.2</NuGetImportHelperVersion>
<NuGetImportHelperVersion>1.0.0.3</NuGetImportHelperVersion>

<NuGetForceImportBeforeCppPropsFallback>$(MSBuildThisFileDirectory)Fallback\NuGetImportBeforeCppProps.props</NuGetForceImportBeforeCppPropsFallback>
<NuGetForceImportAfterCppPropsFallback>$(MSBuildThisFileDirectory)Fallback\NuGetImportAfterCppProps.props</NuGetForceImportAfterCppPropsFallback>
Expand Down
38 changes: 38 additions & 0 deletions YY.NuGet.Import.Helper.targets
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,42 @@
<Error Condition="'$(NuGetImportBeforeCppPropsComplete)' != 'true' and '$(NuGetImportBeforeCppProps)' != ''" Text="$(NuGetImportBeforeCppPropsHelpText)" />
<Error Condition="'$(NuGetImportAfterCppPropsComplete)' != 'true' and '$(NuGetImportAfterCppProps)' != ''" Text="$(NuGetImportAfterCppPropsHelpText)" />
</Target>

<!--处理传统NuGet引用的Content-->
<Target Name="YY_ResolveNuGetPackagesTextContent" AfterTargets="BeforeClCompile" Outputs="'%(Text.FileName)'" >
<PropertyGroup>
<ThisNuGetPackageId>%(Text.FileName)</ThisNuGetPackageId>
</PropertyGroup>

<ItemGroup>
<NuGetExConnentFiles Update="@(NuGetExConnentFiles)" Condition="'%(NuGetExConnentFiles.NuGetPackageId)' == '$(ThisNuGetPackageId)'">
<NuGetIncludeThisFile>true</NuGetIncludeThisFile>
</NuGetExConnentFiles>
</ItemGroup>
</Target>

<!--处理NuGet PackageReference引用的Content-->
<Target Name="YY_ResolveNuGetPackagesPackageReferenceContent" AfterTargets="BeforeClCompile" Outputs="'%(Content.FileName)'">
<PropertyGroup>
<ThisNuGetPackageId>%(Content.FileName)</ThisNuGetPackageId>
<ThisNuGetPackageId Condition="'%(Content.FileName)' != '%(Content.NuGetPackageId)'"></ThisNuGetPackageId>
<ThisNuGetPackageVersion>%(Content.NuGetPackageVersion)</ThisNuGetPackageVersion>
</PropertyGroup>

<ItemGroup Condition="'$(ThisNuGetPackageId)' != ''">
<NuGetExConnentFiles Update="@(NuGetExConnentFiles)" Condition="'%(NuGetExConnentFiles.NuGetPackageId)' == '$(ThisNuGetPackageId)'">
<NuGetIncludeThisFile>true</NuGetIncludeThisFile>
<NuGetPackageVersion Condition="'$(ThisNuGetPackageVersion)' != ''">$(ThisNuGetPackageVersion)</NuGetPackageVersion>
</NuGetExConnentFiles>
</ItemGroup>
</Target>

<!--处理将项插入内存中-->
<Target Name="YY_ResolveNuGetPackages" AfterTargets="BeforeClCompile">
<CreateItem
Condition="'%(NuGetExConnentFiles.NuGetIncludeThisFile)' == 'true'"
Include="@(NuGetExConnentFiles)">
<Output TaskParameter="Include" ItemName="%(NuGetExConnentFiles.BuildAction)"/>
</CreateItem>
</Target>
</Project>
73 changes: 73 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,76 @@

> 请严格按上述内容使用,不要破坏 NuGetImportAfterCppTargets 链,以免影响到其他NuGet包。
### 2.5. 为 C++ NuGetPackge 添加 contentFiles 支持。

以 Detours 为例,我们只需在Detours.Static.targets中添加如下内容:

```xml
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<IncludePath>$(MSBuildThisFileDirectory);$(IncludePath)</IncludePath>
</PropertyGroup>
<ItemGroup>
<NuGetExConnentFiles Include="$(MSBuildThisFileDirectory)Detours\*.cpp" Exclude="$(MSBuildThisFileDirectory)Detours\uimports.cpp">
<!--NuGetPackageId必须这样写,否则罢工!-->
<NuGetPackageId>$(MSBuildThisFileName)</NuGetPackageId>
<!--配置为ClCompile项,一般来说,C与CPP都应该这样!-->
<BuildAction>ClCompile</BuildAction>
<!--关闭预编译头,强烈建议关闭,因为库一般不能使用这种玩意。-->
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<!--关闭SDL,自己根据库决定,一般也推荐关闭。-->
<SDLCheck>false</SDLCheck>
<!--关闭符合模式,具体根据库决定,一般推荐关闭。-->
<ConformanceMode>false</ConformanceMode>
<!--配置obj输出目录,以免文件重名,强烈建议这样保留。-->
<ObjectFileName>$(IntDir)$(MSBuildThisFileName)\</ObjectFileName>
</NuGetExConnentFiles>
</ItemGroup>
</Project>
```

Detours.Static.nuspec 内容如下:

```xml
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/01/nuspec.xsd">
<metadata minClientVersion="2.5">
<id>Detours.Static</id>
<version>4.0.1.19060</version>
<title>Detours Source Package</title>
<summary>Detours is a software package for monitoring and instrumenting API calls on Windows.</summary>
<authors>Microsoft</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<license type="expression">MIT</license>
<projectUrl>https://github.com/microsoft/Detours</projectUrl>
<description>Detours is a software package for monitoring and instrumenting API calls on Windows. Detours has been used by many ISVs and is also used by product teams at Microsoft. Detours is now available under a standard open source license (MIT). This simplifies licensing for programmers using Detours and allows the community to support Detours using open source tools and processes.

Detours is compatible with the Windows NT family of operating systems: Windows NT, Windows XP, Windows Server 2003, Windows 7, Windows 8, and Windows 10. It cannot be used by Window Store apps because Detours requires APIs not available to those applications. This repo contains the source code for version 4.0.1 of Detours.

For technical documentation on Detours, see the Detours Wiki. For directions on how to build and run samples, see the samples README.txt file.</description>
<copyright>Copyright (c) Microsoft Corporation. All rights reserved.</copyright>
<tags>Microsoft Detours native nativepackage</tags>
<repository type="git" url="https://github.com/microsoft/Detours.git" branch="master" commit="edc8b07ae7e7325d9b9d551b46122a82665161b8" />
<contentFiles>
<!--故意添加一个 Detours.Static.txt(文件名需要跟包名一致),我们将通过它来检测 contentFiles 特性开启以及关闭-->
<files include="any\any\Detours.Static.txt" buildAction="Content" copyToOutput="false"/>
</contentFiles>
<dependencies>
<!--让C++ 包支持 contentFiles 至少需要 1.0.0.3 版本-->
<dependency id="YY.NuGet.Import.Helper" version="1.0.0.3" />
</dependencies>
</metadata>
<files>
<file src=".\src\**" target="build\native\Detours" exclude=".\src\Makefile"/>
<file src=".\detours.Static.targets" target="build\native\Detours.Static.targets"/>
<file src=".\Detours.Static.txt" target="contentFiles\any\any\Detours.Static"/>
<file src=".\Detours.Static.txt" target="Content\any\any\Detours.Static"/>
</files>
</package>
```


## 3. 更新日志
### v1.0.0.1 - 2020-01-02 首次发布
* 添加 $(VCTargetsPath)\Microsoft.Cpp.props 之前导入时机
Expand All @@ -148,3 +218,6 @@

### v1.0.0.2 - 2020-01-14
* 解决Bug,Fallback 重复导入警告问题。

### v1.0.0.3 - 2020-09-16
* 新增Fea,为C++添加 contentFiles 特性支持。

0 comments on commit 6a9d05c

Please sign in to comment.