xaml - 错误 MSB4095:如何在 Visual Studio 项目属性对话框中正确添加其他设置?
问题描述
我正在尝试将其他配置项添加到项目中,目的是创建一个用户友好的 Dlib 项目来编译和链接 Dlib。
这是我的.xaml
文件,基于我在 Visual Studio 安装目录中找到的内容:
<?xml version="1.0" encoding="utf-8"?>
<ProjectSchemaDefinitions xmlns="clr-namespace:Microsoft.Build.Framework.XamlTypes;assembly=Microsoft.Build.Framework">
<Rule Name="DLibOptionsRule" PageTemplate="generic" DisplayName="DLib settings">
<Rule.Categories>
<Category Name="dlib" DisplayName="DLib" />
</Rule.Categories>
<Rule.DataSource>
<DataSource Persistence="ProjectFile" ItemType="" />
</Rule.DataSource>
<BoolProperty Name="DlibCUDAEnabled" DisplayName="Use CUDA" Default="false" Category="dlib" IncludeInCommandLine="false"/>
<StringProperty Name="DlibCUDAPath" DisplayName="CUDA path" Description="Path to the CUDA library" Category="dlib" IncludeInCommandLine="false">
<StringProperty.ValueEditors>
<ValueEditor EditorType="DefaultStringPropertyEditor" DisplayName="<Edit...>"/>
<ValueEditor EditorType="DefaultFilePropertyEditor" DisplayName="<Browse...>"/>
</StringProperty.ValueEditors>
</StringProperty>
</Rule>
</ProjectSchemaDefinitions>
然后我将其包含在此.targets
文件中:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PropertyPageSchema Include="$(MSBuildThisFileDirectory)\DlibOptions.xaml" />
</ItemGroup>
<Target Name="DlibSetDefines" BeforeTargets="PreBuildEvent">
<Message Text="Setting DLIB_USE_CUDA=%(DlibCUDAEnabled)" />
<ItemGroup>
<ClCompile>
<PreprocessorDefinitions>DLIB_USE_CUDA=%(DlibCUDAEnabled);%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemGroup>
</Target>
</Project>
最后,我在 Visual Studio 项目的结尾部分上方包含了目标:
<Import Project="DLibOptions.targets" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
我可以在项目属性对话框中看到配置项:
但是,当我尝试构建时,出现此错误:
error MSB4095: The item metadata %(DlibCUDAEnabled) is being referenced without an item name. Specify the item name by using %(itemname.DlibCUDAEnabled).
如果您愿意看一下,可以在这里找到完整的项目:https ://github.com/Darker/dlib-vs-solution
解决方案
问题是
<Message Text="Setting DLIB_USE_CUDA=%(DlibCUDAEnabled)" />
永远无法工作,因为它没有指定要显示的项目,因此 Message 任务不知道要循环什么。您可能打算:
<Message Text="Setting DLIB_USE_CUDA=%(ClCompile.DlibCUDAEnabled)" />
但这并不是超级有用,因为它只会列出标志。这更有趣,并显示标志 + 源文件:
<Message Text="Setting DLIB_USE_CUDA=%(ClCompile.DlibCUDAEnabled) for %(ClCompile.Identity)" />
推荐阅读
- javascript - 无法通过酶关闭模式菜单
- python - How to add non-english characters on a screen title in pygame?
- c - 单链表:newNode 函数不指向下一个节点
- c# - 异步事件处理程序有时会挂在 Xamarin.Forms
- c# - c# Get File Last Access or Usuability
- ms-access - MS Access- Join Tables where a column in one table is between two others
- elixir - designing ecto queries on my schema models to support preloading
- r - Change the version of the C compiler used by RStan
- python - Is there a way to modify the HTTP_REFERRER before redirecting in Django?
- python - 使用没有 selenium 的 Python 下载文件,例如 Chrome 的“将链接另存为”