简体   繁体   English

xbuild无法嵌入共享项目中的资源

[英]xbuild fails to embed resources from shared project

I have a C# project A located in FolderA which references a shared project B . 我在FolderA中有一个C#项目A ,它引用了一个共享项目B。 The files of the shared project are located in FolderB . 共享项目的文件位于FolderB中 The shared project B contains a file C.gz with the properties 共享项目B包含具有以下属性的文件C.gz

Build Action Embedded Resource 构建动作 嵌入式资源
Copy to Output Directory Do Not Copy 复制到输出目录 不复制

When I try to build project A using xbuild (specifically versions 4.8 and 4.8.1, x86 and x64 architectures): 当我尝试使用xbuild (特别是版本4.8和4.8.1,x86和x64体系结构)构建项目A时

xbuild A.csproj

I get the following build error: 我收到以下构建错误:

C:\\Program Files (x86)\\Mono\\lib\\mono\\xbuild\\14.0\\bin\\Microsoft.Common.targets (CopyNonResxEmbeddedResources target) -> C:\\ Program Files(x86)\\ Mono \\ lib \\ mono \\ xbuild \\ 14.0 \\ bin \\ Microsoft.Common.targets(CopyNonResxEmbeddedResources目标)->

C:\\Program Files (x86)\\Mono\\lib\\mono\\xbuild\\14.0\\bin\\Microsoft.Common.targets: error : Cannot copy FolderA\\C.gz to FolderA\\obj\\Release\\C.gz, as the source file doesn't exist. C:\\ Program Files(x86)\\ Mono \\ lib \\ mono \\ xbuild \\ 14.0 \\ bin \\ Microsoft.Common.targets:错误:无法将FolderA \\ C.gz复制到FolderA \\ obj \\ Release \\ C.gz作为源文件不存在。

ie xbuild searches for the embedded resource file in FolderA although it is apparently located in FolderB together with the other files of the shared project B . xbuildFolderA中搜索嵌入式资源文件,尽管它显然与共享项目B的其他文件一起位于FolderB中

It is not a feasible option for me to move the embedded resource file to project A , as the shared project is referenced from several other projects as well. 对于我来说,将嵌入式资源文件移动到项目A并不是可行的选择,因为共享项目也从其他几个项目中引用。

Is there something else I can do to make project A build successfully with xbuild ? 有没有别的东西,我可以做,使项目Axbuild成功打造?


Side note: is this an expected behavior in xbuild , or is it a bug? 旁注:这是xbuild中的预期行为,还是错误? With msbuild I don't have this problem. 使用msbuild,我没有这个问题。

This issue appears to be a flaw in the current xbuild implementation, so I needed to apply a workaround specific for this problem. 此问题似乎是当前xbuild实现中的一个缺陷,因此我需要针对此问题应用特定的解决方法。

Since xbuild expects the embedded resource file to be available in the FolderA folder, I simply add a pre-build step in the project file: 由于xbuild希望嵌入式资源文件在FolderA文件夹中可用,因此我只需在项目文件中添加一个预构建步骤:

<ItemGroup>
  <FilesToCopy Include="..\FolderB\C.gz" />
</ItemGroup>
<Target Name="BeforeBuild">
  <Copy SourceFiles="@(FilesToCopy)" DestinationFolder="."/>
</Target>

Optionally, one could also consider a cleanup after building by removing the copied file in the post-build. 也可以选择在构建后通过在构建后删除复制的文件来考虑进行清理。

Note! 注意! To ensure that the pre-build step is properly accounted for, make sure to place it after this line: 为确保正确解释了预构建步骤,请确保将其放置此行之后:

<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM