我正在导入MSBuild目标文件以将属性设置为VS C ++项目 - 即include和libs文件夹。 (我正在使用Nuget用于本机包,这就是它在那里的工作方式)。 我找不到在IDE中查看的方法,即项目从属性文件中获取的有效属性值。 当我查看项目属性(例如包含文件夹)时,它们是空的。 但目标文件正在运行,因为我能够使用成功指定的include,lib文件夹。
如何查看IDE中的值?
以下是其他细节: 我安装了 Microsoft.Azure.C.SharedUtility(1.0.19)Nuget包在一个空的C ++项目中。这导致以下部分添加到vcxproj文件中:
<ImportGroup Label="ExtensionTargets">
<Import Project="..\packages\Microsoft.Azure.C.SharedUtility.1.0.19\build\native\Microsoft.Azure.C.SharedUtility.targets" Condition="Exists('..\packages\Microsoft.Azure.C.SharedUtility.1.0.19\build\native\Microsoft.Azure.C.SharedUtility.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Azure.C.SharedUtility.1.0.19\build\native\Microsoft.Azure.C.SharedUtility.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Azure.C.SharedUtility.1.0.19\build\native\Microsoft.Azure.C.SharedUtility.targets'))" />
</Target>
目标文件本身是:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" InitialTargets="Microsoft_Azure_C_SharedUtil_Init">
<PropertyGroup Label="Default initializers for properties">
<Linkage-Microsoft_Azure_C_SharedUtil_Init Condition="'$(Linkage-Microsoft_Azure_C_SharedUtil_Init)' == ''">static</Linkage-Microsoft_Azure_C_SharedUtil_Init>
<CallingConvention-Microsoft_Azure_C_SharedUtil Condition="'$(CallingConvention-Microsoft_Azure_C_SharedUtil)' == ''">cdecl</CallingConvention-Microsoft_Azure_C_SharedUtil>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)../../build/native/include/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<ResourceCompile>
<AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)../../build/native/include/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Label="Win32Debug" Condition="(( $(Configuration.ToLower().IndexOf('debug')) > -1 ) And ('$(Platform)' == 'Win32' ) )">
<Link>
<AdditionalDependencies>Secur32.lib;Ws2_32.lib;$(MSBuildThisFileDirectory)../../build/native/Win32/Debug/aziotsharedutil.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Label="Win32Release" Condition="(( $(Configuration.ToLower().IndexOf('debug')) == -1 ) And ('$(Platform)' == 'Win32' ) )">
<Link>
<AdditionalDependencies>Secur32.lib;Ws2_32.lib;$(MSBuildThisFileDirectory)../../build/native/Win32/Release/aziotsharedutil.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Label="Win64Debug" Condition="(( $(Configuration.ToLower().IndexOf('debug')) > -1 ) And ('$(Platform)' == 'x64' ) )">
<Link>
<AdditionalDependencies>Secur32.lib;Ws2_32.lib;$(MSBuildThisFileDirectory)../../build/native/x64/Debug/aziotsharedutil.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Label="Win64Release" Condition="(( $(Configuration.ToLower().IndexOf('debug')) == -1 ) And ('$(Platform)' == 'x64' ) )">
<Link>
<AdditionalDependencies>Secur32.lib;Ws2_32.lib;$(MSBuildThisFileDirectory)../../build/native/x64/Release/aziotsharedutil.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Label="ARMDebug" Condition="(( $(Configuration.ToLower().IndexOf('debug')) > -1 ) And ('$(Platform)' == 'ARM' ) )">
<Link>
<AdditionalDependencies>Secur32.lib;Ws2_32.lib;$(MSBuildThisFileDirectory)../../build/native/arm/Debug/aziotsharedutil.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Label="ARMRelease" Condition="(( $(Configuration.ToLower().IndexOf('debug')) == -1 ) And ('$(Platform)' == 'ARM' ) )">
<Link>
<AdditionalDependencies>Secur32.lib;Ws2_32.lib;$(MSBuildThisFileDirectory)../../build/native/arm/Release/aziotsharedutil.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Label="ARM64Debug" Condition="(( $(Configuration.ToLower().IndexOf('debug')) > -1 ) And ('$(Platform)' == 'ARM64' ) )">
<Link>
<AdditionalDependencies>Secur32.lib;Ws2_32.lib;$(MSBuildThisFileDirectory)../../build/native/arm64/Debug/aziotsharedutil.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Label="ARM64Release" Condition="(( $(Configuration.ToLower().IndexOf('debug')) == -1 ) And ('$(Platform)' == 'ARM64' ) )">
<Link>
<AdditionalDependencies>Secur32.lib;Ws2_32.lib;$(MSBuildThisFileDirectory)../../build/native/arm64/Release/aziotsharedutil.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<UsingTask TaskName="Microsoft_Azure_Shared_Util_Contains" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" TaskFactory="CodeTaskFactory">
<ParameterGroup>
<Text Output="false" ParameterType="System.String" />
<Library Output="false" Required="true" ParameterType="System.String" />
<Value Output="false" Required="true" ParameterType="System.String" />
<Result Output="true" ParameterType="System.String" />
</ParameterGroup>
<Task>
<Code>Result = ((Text ?? "").Split(';').Contains(Library) ) ? Value : String.Empty;</Code>
</Task>
</UsingTask>
<Target Name="Microsoft_Azure_C_SharedUtil_Init">
<Microsoft_Azure_Shared_Util_Contains Text="Linkage-dynamic" Library="Microsoft_Azure_Shared_Util" Value="dynamic" Condition="'$(Linkage-Microsoft_Azure_C_SharedUtil_Init)'==''">
<Output TaskParameter="Result" PropertyName="Linkage-Microsoft_Azure_C_SharedUtil_Init" />
</Microsoft_Azure_Shared_Util_Contains>
<Microsoft_Azure_Shared_Util_Contains Text="Linkage-static" Library="Microsoft_Azure_Shared_Util" Value="static" Condition="'$(Linkage-Microsoft_Azure_C_SharedUtil_Init)'==''">
<Output TaskParameter="Result" PropertyName="Linkage-Microsoft_Azure_C_SharedUtil_Init" />
</Microsoft_Azure_Shared_Util_Contains>
<Microsoft_Azure_Shared_Util_Contains Text="Linkage-ltcg" Library="Microsoft_Azure_Shared_Util" Value="ltcg" Condition="'$(Linkage-Microsoft_Azure_C_SharedUtil_Init)'==''">
<Output TaskParameter="Result" PropertyName="Linkage-Microsoft_Azure_C_SharedUtil_Init" />
</Microsoft_Azure_Shared_Util_Contains>
<Microsoft_Azure_Shared_Util_Contains Text="Linkage-sxs" Library="Microsoft_Azure_Shared_Util" Value="sxs" Condition="'$(Linkage-Microsoft_Azure_C_SharedUtil_Init)'==''">
<Output TaskParameter="Result" PropertyName="Linkage-Microsoft_Azure_C_SharedUtil_Init" />
</Microsoft_Azure_Shared_Util_Contains>
<Microsoft_Azure_Shared_Util_Contains Text="CallingConvention-cdecl" Library="Microsoft_Azure_Shared_Util" Value="cdecl" Condition="'$(CallingConvention-Microsoft_Azure_Shared_Util)'==''">
<Output TaskParameter="Result" PropertyName="CallingConvention-Microsoft_Azure_Shared_Util" />
</Microsoft_Azure_Shared_Util_Contains>
<Microsoft_Azure_Shared_Util_Contains Text="CallingConvention-stdcall" Library="Microsoft_Azure_Shared_Util" Value="stdcall" Condition="'$(CallingConvention-Microsoft_Azure_Shared_Util)'==''">
<Output TaskParameter="Result" PropertyName="CallingConvention-Microsoft_Azure_Shared_Util" />
</Microsoft_Azure_Shared_Util_Contains>
<Microsoft_Azure_Shared_Util_Contains Text="CallingConvention-fastcall" Library="Microsoft_Azure_Shared_Util" Value="fastcall" Condition="'$(CallingConvention-Microsoft_Azure_Shared_Util)'==''">
<Output TaskParameter="Result" PropertyName="CallingConvention-Microsoft_Azure_Shared_Util" />
</Microsoft_Azure_Shared_Util_Contains>
<Microsoft_Azure_Shared_Util_Contains Text="CallingConvention-thiscall" Library="Microsoft_Azure_Shared_Util" Value="thiscall" Condition="'$(CallingConvention-Microsoft_Azure_Shared_Util)'==''">
<Output TaskParameter="Result" PropertyName="CallingConvention-Microsoft_Azure_Shared_Util" />
</Microsoft_Azure_Shared_Util_Contains>
<Microsoft_Azure_Shared_Util_Contains Text="CallingConvention-clrcall" Library="Microsoft_Azure_Shared_Util" Value="clrcall" Condition="'$(CallingConvention-Microsoft_Azure_Shared_Util)'==''">
<Output TaskParameter="Result" PropertyName="CallingConvention-Microsoft_Azure_Shared_Util" />
</Microsoft_Azure_Shared_Util_Contains>
</Target>
<Target Name="Microsoft_Azure_Shared_Util_redist_AfterBuild" AfterTargets="AfterBuild" />
<Target Name="Microsoft_Azure_Shared_Util_redist_AfterBuild_Win32_and_Debug" Label="Win32 and Debug" Condition="'$(Platform.ToLower())' == 'win32' And ( $(Configuration.ToLower().IndexOf('debug')) > -1 )" AfterTargets="Microsoft_Azure_Shared_Util_redist_AfterBuild">
</Target>
<Target Name="Microsoft_Azure_Shared_Util_redist_AfterBuild_Win32_and_Release" Label="Win32 and Release" Condition="'$(Platform.ToLower())' == 'win32' And ( $(Configuration.ToLower().IndexOf('debug')) == -1 )" AfterTargets="Microsoft_Azure_Shared_Util_redist_AfterBuild">
</Target>
<Target Name="Microsoft_Azure_Shared_Util_redist_AfterBuild_Win64_and_Debug" Label="Win64 and Debug" Condition="'$(Platform.ToLower())' == 'x64' And ( $(Configuration.ToLower().IndexOf('debug')) > -1 )" AfterTargets="Microsoft_Azure_Shared_Util_redist_AfterBuild">
</Target>
<Target Name="Microsoft_Azure_Shared_Util_redist_AfterBuild_Win64_and_Release" Label="Win64 and Release" Condition="'$(Platform.ToLower())' == 'x64' And ( $(Configuration.ToLower().IndexOf('debug')) == -1 )" AfterTargets="Microsoft_Azure_Shared_Util_redist_AfterBuild">
</Target>
<Target Name="Microsoft_Azure_Shared_Util_redist_AfterBuild_ARM_and_Debug" Label="ARM and Debug" Condition="'$(Platform.ToLower())' == 'ARM' And ( $(Configuration.ToLower().IndexOf('debug')) > -1 )" AfterTargets="Microsoft_Azure_Shared_Util_redist_AfterBuild">
</Target>
<Target Name="Microsoft_Azure_Shared_Util_redist_AfterBuild_ARM_and_Release" Label="ARM and Release" Condition="'$(Platform.ToLower())' == 'ARM' And ( $(Configuration.ToLower().IndexOf('debug')) == -1 )" AfterTargets="Microsoft_Azure_Shared_Util_redist_AfterBuild">
</Target>
<Target Name="Microsoft_Azure_Shared_Util_redist_AfterBuild_ARM64_and_Debug" Label="ARM64 and Debug" Condition="'$(Platform.ToLower())' == 'ARM64' And ( $(Configuration.ToLower().IndexOf('debug')) > -1 )" AfterTargets="Microsoft_Azure_Shared_Util_redist_AfterBuild">
</Target>
<Target Name="Microsoft_Azure_Shared_Util_redist_AfterBuild_ARM64_and_Release" Label="ARM64 and Release" Condition="'$(Platform.ToLower())' == 'ARM64' And ( $(Configuration.ToLower().IndexOf('debug')) == -1 )" AfterTargets="Microsoft_Azure_Shared_Util_redist_AfterBuild">
</Target>
</Project>
该项目工作正常,包括来自正确的文件夹和引用正确的库,但我无法在IDE中看到有效值。
谢谢, 罗伊。
答案 0 :(得分:1)
如评论中所述,这看起来像是VS中的一个错误(或者可能是特征):由于某种原因导入的文件是在项目自己的ItemDefinitionGroups之后导入的,它具有编译器/链接器设置,它&根据标准的msbuild评估规则,即使在构建中使用了内容,它也不会反映在IDE中。
解决方法很简单:在项目文件中将“导入”更高。实际上,您可以看到Import现在位于ImportGroup中,标记为&#39; ExtensionTargets&#39;但是在文件中还有一个标有&#39; ExtensionSettings&#39;这似乎是针对此类用途量身定制的 - VS会正确显示生成的设置,并且可以在需要时通过standard project property system覆盖用户设置。
可以说(虽然我无法找到支持它的文档),这里最明智的做法是提供2个导入:实际的目标文件,顾名思义包含msbuild在&#39; ExtensionTargets&#39;下导入的目标,以及在&#39; ExtensionSettings&#39;下导入的带有编译器/链接器设置的单独文件。后者不会有.targets扩展名,而是.props扩展名,因为这是最常用的约定。