C# xbuild使用(.html)资源文件失败

C# xbuild使用(.html)资源文件失败,c#,ubuntu,mono,targets,xbuild,C#,Ubuntu,Mono,Targets,Xbuild,我在让xbuild编译web应用程序项目时遇到问题。 我们有一些资源文件,它们是.html文件 当前失败的是'KwasantCore\Resources\HTMLEventInvitation.html' 资源在KwasantCore.csproj中定义为 <Content Include="Resources\HTMLEventInvitation.html" /> 运行xbuild时,出现以下错误: /home/gitlab_ci_runner/gitlab-ci-runner

我在让xbuild编译web应用程序项目时遇到问题。 我们有一些资源文件,它们是.html文件

当前失败的是
'KwasantCore\Resources\HTMLEventInvitation.html'

资源在KwasantCore.csproj中定义为

<Content Include="Resources\HTMLEventInvitation.html" />
运行xbuild时,出现以下错误:

/home/gitlab_ci_runner/gitlab-ci-runner/tmp/builds/project-1/Kwasant.sln (default targets) ->
(Build target) ->
/home/gitlab_ci_runner/gitlab-ci-runner/tmp/builds/project-1/KwasantCore/KwasantCore.csproj (default targets) ->
/usr/lib/mono/xbuild/12.0/bin/Microsoft.Common.targets (GenerateResources target) ->

    /usr/lib/mono/xbuild/12.0/bin/Microsoft.Common.targets: error : Tool exited with code: 1. Output: Error: Invalid ResX input.
Position: Line 123, Column 5.
Inner exception: Could not find a part of the path "/home/gitlab_ci_runner/gitlab-ci-runner/tmp/builds/project-1/KwasantCore/resources/htmleventinvitation.html".
我检查了文件,它就在那里-问题是区分大小写。该资源在.csproj中被正确引用,因此在某个地方,该资源从
'Resources/HTMLEventInvitation.html'
变为
'Resources/HTMLEventInvitation.html'

我已经查看了ubuntu框中的Microsoft.Common.targets文件。第125行是完全不相关的(它显示的是
)。查看GenerateResources目标,它向我显示:

<Target Name = "GenerateResources">
        <GenerateResource
            Sources = "@(ResxWithNoCulture)"
            UseSourcePath = "true"
            OutputResources = "@(ManifestResourceWithNoCultureName->'$(IntermediateOutputPath)%(Identity).resources')"
            Condition = "'@(ResxWithNoCulture)' != '' ">

            <Output TaskParameter = "OutputResources" ItemName = "ManifestResourceWithNoCulture"/>
            <Output TaskParameter = "FilesWritten" ItemName = "FileWrites"/>
        </GenerateResource>

        <GenerateResource
            Sources = "@(ResxWithCulture)"
            UseSourcePath = "true"
            OutputResources = "@(ManifestResourceWithCultureName->'$(IntermediateOutputPath)%(Identity).resources')"
            Condition = "'@(ResxWithCulture)' != '' ">

            <Output TaskParameter = "OutputResources" ItemName = "ManifestResourceWithCulture"/>
            <Output TaskParameter = "FilesWritten" ItemName = "FileWrites"/>
        </GenerateResource>
    </Target>

在“GenerateResources”之前直接调用目标“CopyNonResxEmbeddedResources”

我无法告诉您为什么要这样做,但我的解决方案是更改资源的名称以匹配它所查找的内容

它看起来确实像是在尝试将某些东西处理为Resx

 Tool exited with code: 1. Output: Error: Invalid ResX input.

也许可以检查您的设置?

编译器试图将其解释为资源文件而不是资源。资源文件是一个.txt或.resx文件,用于指定特定格式的资源(例如字符串、图像),而不是资源本身

GenerateResource
任务根本不应该在资源上运行,因为它的目的是将.txt或.resx文件转换为.resource文件以嵌入到程序集中


如果没有实际的资源文件(.txt或.resx),则应将该任务从项目的生成中删除。否则,您只需要确保只将正确的文件传递给它。如果不能看到更多的配置,我无法确切地告诉您如何执行此操作,但这是一项常见的配置任务,因此您应该能够在Google上找到指导。

我不知道为什么会发生这种情况(我的大脑无法再容纳任何构建系统的配置细微差别),但我一路上学会的一个技巧是:

MONO\u IOMAP=case xbuild…

该环境变量告诉Mono在搜索文件时不区分大小写。使用它来解决跨Windows Mac Linux文件系统的区分大小写移植问题,但是
MONO\u IOMAP
工具提供了其他几个文件系统和I/O映射操作


如果不起作用,您可以尝试,这是一个Linux用户空间不区分大小写的文件系统。不过,我从未使用过它。

我无法回答“为什么”,但我可以提供一些解决办法。尝试使用
MONO\u IOMAP=case xbuild…
构建MONO以折叠箱子。如果失败,请尝试使用提供一个故意不区分大小写的文件系统。除了前面的注释外,您还可以查看一下。@bishop that为我完美地修复了它。你能补充这个作为回答吗,这样我就可以接受它并结束这个问题了?干杯,太棒了,很高兴解决了!我已经发布了答案。
<CreateItem Include="@(ResourcesWithNoCulture)" Condition="'%(Extension)' == '.resx'">
    <Output TaskParameter="Include" ItemName="ResxWithNoCulture"/>
</CreateItem>

<CreateItem Include="@(ResourcesWithNoCulture)" Condition="'%(Extension)' != '.resx'">
    <Output TaskParameter="Include" ItemName="NonResxWithNoCulture"/>
</CreateItem>

<CreateItem Include="@(ResourcesWithCulture)" Condition="'%(Extension)' == '.resx'">
    <Output TaskParameter="Include" ItemName="ResxWithCulture"/>
</CreateItem>

<CreateItem Include="@(ResourcesWithCulture)" Condition="'%(Extension)' != '.resx'">
    <Output TaskParameter="Include" ItemName="NonResxWithCulture"/>
</CreateItem>
<Target Name = "CopyNonResxEmbeddedResources"
        Condition = "'@(NonResxWithCulture)' != '' or '@(NonResxWithNoCulture)' != '' or '@(ManifestNonResxWithCulture)' != '' or '@(ManifestNonResxWithNoCulture)' != ''">

        <MakeDir Directories="$(IntermediateOutputPath)%(ManifestNonResxWithCulture.Culture)"/>
        <Copy SourceFiles = "@(NonResxWithCulture)"
            DestinationFiles = "@(ManifestNonResxWithCulture->'$(IntermediateOutputPath)%(Identity)')"
            SkipUnchangedFiles="$(SkipCopyUnchangedFiles)">
            <Output TaskParameter = "DestinationFiles" ItemName = "ManifestNonResxWithCultureOnDisk"/>
            <Output TaskParameter = "DestinationFiles" ItemName = "FileWrites"/>
        </Copy>

        <Copy SourceFiles = "@(NonResxWithNoCulture)"
            DestinationFiles = "@(ManifestNonResxWithNoCulture->'$(IntermediateOutputPath)%(Identity)')"
            SkipUnchangedFiles="$(SkipCopyUnchangedFiles)">
            <Output TaskParameter = "DestinationFiles" ItemName = "ManifestNonResxWithNoCultureOnDisk"/>
            <Output TaskParameter = "DestinationFiles" ItemName = "FileWrites"/>
        </Copy>
    </Target>
 Tool exited with code: 1. Output: Error: Invalid ResX input.