Visual studio 项目构建错误-与NETStandard.Library2.0.1有关(我想!)
我在尝试构建项目时遇到了一个奇怪的错误:Visual studio 项目构建错误-与NETStandard.Library2.0.1有关(我想!),visual-studio,msbuild,.net-standard,csproj,Visual Studio,Msbuild,.net Standard,Csproj,我在尝试构建项目时遇到了一个奇怪的错误: Error: The reference to the built-in metadata "FileName" at position 1 is not allowed in this condition "'%(FileName)' != 'netstandard'". C:\github\VS\API\VS.API.Public\VS.API.Public.csproj at Microsoft.Build.Shared.ProjectErro
Error: The reference to the built-in metadata "FileName" at position 1 is not allowed in this condition "'%(FileName)' != 'netstandard'". C:\github\VS\API\VS.API.Public\VS.API.Public.csproj
at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object[] args)
at Microsoft.Build.Evaluation.Parser.Parse(String expression, ParserOptions optionSettings, ElementLocation elementLocation)
at Microsoft.Build.Evaluation.ConditionEvaluator.EvaluateConditionCollectingConditionedProperties[P,I](String condition, ParserOptions options, Expander`2 expander, ExpanderOptions expanderOptions, Dictionary`2 conditionedPropertiesTable, String evaluationDirectory, ElementLocation elementLocation, ILoggingService loggingServices, BuildEventContext buildEventContext, ProjectRootElementCache projectRootElementCache)
at Microsoft.Build.Execution.ProjectInstance.EvaluateCondition(String condition)
at JetBrains.Platform.MsBuild.TaskCommon.ProjectModel.Bindings.AddWildcardItemsFromXml(ProjectRootElement element, Boolean isImported, ProjectInstance projectInstance, List`1 items)
at JetBrains.Platform.MsBuild.TaskCommon.ProjectModel.Bindings.BindWildcardItems(Project project, ProjectInstance projectInstance)
at JetBrains.Platform.MsBuild.TaskCommon.ProjectModel.Bindings.Bind(Project project, ProjectInstance projectInstance, List`1 targetErrors, List`1 targetWarnings, Dictionary`2 resultsByTarget)
at JetBrains.Platform.MsBuild.TaskCommon.ProjectModel.Bindings.Bind(Project project, ProjectInstance projectInstance)
at JetBrains.Platform.MsBuild.TaskCommon.Build.BuildSessionHost.HandleSubmissionFinished(RdBuildRequest request, ProjectWithEvents projectWithEvents, Boolean succeeded, RdTask`1 rdTask)
我不知道这个错误意味着什么,甚至不知道从哪里开始。这是一个Web API项目,当我对该项目进行重建时,它会显示在Visual Studio的“生成结果”窗口中
该错误提到了此条件的问题:“%(文件名)!=”.csproj文件中的netstandard“
。但是,在.csproj文件中进行搜索时,不会出现这种情况
如果我搜索解决方案文件夹中的所有文件,我可以在C:\github\vs\packages\NETStandard.Library.2.0.1\build
中找到它:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<NETStandardLibraryPackageVersion>2.0.1</NETStandardLibraryPackageVersion>
</PropertyGroup>
<ItemGroup Condition="'$(_NetStandardLibraryRefPath)' != ''">
<Reference Include="$(_NetStandardLibraryRefPath)*.dll">
<!-- Private = false to make these reference only -->
<Private>false</Private>
<!-- hide these from Assemblies view in Solution Explorer, they will be shown under packages -->
<Visible>false</Visible>
<Facade Condition="'%(FileName)' != 'netstandard'">true</Facade>
<NuGetPackageId>NETStandard.Library</NuGetPackageId>
<NuGetPackageVersion>$(NETStandardLibraryPackageVersion)</NuGetPackageVersion>
</Reference>
<ReferenceCopyLocalPaths Condition="'$(_NetStandardLibraryLibPath)' != ''" Include="$(_NetStandardLibraryLibPath)*.dll">
<Private>false</Private>
<Facade Condition="'%(FileName)' != 'netstandard'">true</Facade>
<NuGetPackageId>NETStandard.Library</NuGetPackageId>
<NuGetPackageVersion>$(NETStandardLibraryPackageVersion)</NuGetPackageVersion>
</ReferenceCopyLocalPaths>
</ItemGroup>
</Project>
2.0.1
假的
假的
真的
NETStandard.Library
$(NETStandardLibraryPackageVersion)
假的
真的
NETStandard.Library
$(NETStandardLibraryPackageVersion)
但我对.targets文件的工作方式了解不够,无法解决此问题。。。通常情况下,它只是工作
我也找不到任何相关的结果,如果我试图谷歌这个错误。有人知道这里出了什么问题吗
我正在使用Visual Studio Professional 15.6.0。该项目的目标是.net462
但我对.targets文件的工作方式了解不够,无法解决这个问题
根据NuGet文件:
包还可能包括\build中的目标和道具文件
NuGet将自动导入到使用
包裹
这意味着NuGet将把适当的.props
和目标文件导入到项目中。因此,当您将包NETStandard.Library.2.0.1
安装到项目中时,NETStandard.Library.targets
文件(位于该包的\buil
d文件夹中)将导入到项目文件中,卸载项目,编辑它,然后您将发现以下代码:
<Import Project="..\packages\NETStandard.Library.2.0.1\build\NETStandard.Library.targets" Condition="Exists('..\packages\NETStandard.Library.2.0.1\build\NETStandard.Library.targets')" />
资料来源:
或者,您可以创建存储此自定义元数据值的属性:
<PropertyGroup>
<FimeName>%(FileName)</FimeName>
</PropertyGroup>
<ItemGroup>
...
<Facade Condition="'$(FileName)' != 'netstandard'">true</Facade>
...
</ItemGroup>
%(文件名)
...
真的
...
资料来源:
此外,如果您可以确保没有使用该.targets
文件,您可以尝试删除项目文件中的
。谢谢您的回答。我尝试添加%(文件名)…
来存储元数据的值,这非常有效。但是,它涉及编辑NETStandard.Library.targets
文件,该文件由NuGet安装在packages文件夹中,因此如果重新安装,可能会被覆盖,并且不会添加到源代码管理中。有没有办法只编辑.csproj文件来做类似的事情?@BG100,是的,你说的没错,如果重新安装.targets文件,它会被覆盖。要解决此问题,可以覆盖项目文件.csporj中结束标记
之前的脚本。或者您可以下载该包,覆盖.targets文件,然后用自定义名称保存该包,使用自定义包而不是包NETStandard.Library
Ok,明白了。谢谢你的帮助:)
<PropertyGroup>
<FimeName>%(FileName)</FimeName>
</PropertyGroup>
<ItemGroup>
...
<Facade Condition="'$(FileName)' != 'netstandard'">true</Facade>
...
</ItemGroup>