【发布时间】:2020-08-23 00:11:25
【问题描述】:
我有一个库并同时为它创建一个 Nuget 有 MSBuild 和 .targets 文件定义要移动的内容。
构建\proj.targets 文件:
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ExResources Include="$(MSBuildThisFileDirectory)..\staticwebassets\ExFiles\*" />
<Message Importance="high" Text="@(ExResources)" />
<DefaultValues Include="$(MSBuildThisFileDirectory)..\staticwebassets\*" />
</ItemGroup>
<Target Name="CopyResources" BeforeTargets="BeforeCompile" >
<Message Importance="high" Text="Copying resources to consumer app!" />
<Message Importance="high" Text="First up, all resources, except the default config" />
<Message Importance="high" Text="@(ExResources)" />
<Copy SourceFiles="@(ExResources)"
DestinationFolder="$(MsBuildProjectDirectory)\wwwroot\component_library\" />
<Message Importance="high" Text="Now what's left is the default config, which we only write if it doesn't exist yet" />
<Message Importance="high" Text="@(DefaultValues)" />
<Copy SourceFiles="@(DefaultValues)"
DestinationFolder="$(MsBuildProjectDirectory)\wwwroot\"/>
</Target>
</Project>
在 .csProj 文件中:
<ItemGroup>
<Folder Include="build\" />
</ItemGroup>
<ItemGroup>
<Content Include="build\*.targets" PackagePath="build\" />
</ItemGroup>
有 2 个问题:
首先,运行 msbuild 时出现以下错误:
(ExFiles 位于库的根目录中)
proj.targets(46,7):
error MSB4184:
The expression "[System.IO.Path]::GetDirectoryName('')" cannot be evaluated.
The path is not of a legal form.
第二,这个错误不告诉你是哪个路径。 使用各种形式、命令和工具构建,例如:
dotnet msbuild "D:\SSS\Proj.csproj" -v:diag -bl
还尝试了 MSBuild 结构化日志查看器,它没有显示任何其他信息。
.targets 文件中的任何消息都不会显示在 VS 输出窗口中。
所以,我从未见过"Copying resources to consumer app!" 或"@(ExResources)" 的值
【问题讨论】:
标签: visual-studio msbuild nuget