我有一些脚本存储在我标记为嵌入式资源的文件中。我将每个文件嵌套在其关联的下面.cs
文件。不幸的是,由于某种原因,当您以这种方式嵌套文件时,嵌入的资源名称会丢失文件扩展名。这意味着在运行时我无法识别哪些嵌入式资源是脚本,哪些不是脚本。对此我能做什么?
我尝试过的一件事不起作用:ManifestResourceInfo
对象,它有一个FileName
财产。不幸的是这个属性是null
.
我尝试的另一件事是将扩展加倍。 (喜欢:filename.ext.ext
)。这不起作用,第一个之后的一切.
仍然失踪。
I tried naming the resource with something very different, and noticed that the resource name didn't even change. It seems that it is generating the resource name for a nested embedded resource file based off of the "dependent upon" file, which in this case is just a regular .cs
file. I tried doubling the extension of the .cs
file to filename.extrastuff.cs
but the resource name still doesn't change. It insists on clipping everything after the first .
.
不,好吧,我现在看到它实际上是在以type定义在.cs
文件,而不是任一文件的文件名。这就是为什么扩展没有区别。这意味着我无法对这两个文件名执行任何操作来帮助查找资源。
我发现文件丢失扩展名的原因是由于某种原因,当文件嵌套时,VS 在后命名资源type而不是之后file.
我发现在嵌套时唯一允许我仍然拥有扩展名的是手动编辑.csproj
文件并添加一个LogicalName
标签,它允许您覆盖资源名称。
<EmbeddedResource Include="Path\To\NestedFile.ext">
<LogicalName>NestedFile.ext</LogicalName>
<DependentUpon>ParentFile.cs</DependentUpon>
</EmbeddedResource>
不幸的是,没有 IDE 支持此操作,并且我使用的 FileNesting 扩展也不支持写入此标记。
必须对每个文件执行此操作太麻烦了,因此我必须在脚本文件中添加一个标识符来将它们标识为脚本,而不是依赖文件扩展名。
最终我意识到,由于在我的例子中,我正在验证单元测试中的脚本文件,因此我可以简单地扫描文件系统而不是资源清单,并完全避免此问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)