【问题标题】:How to automatically include a copy of resource files when compiling without embedding them?如何在编译时自动包含资源文件的副本而不嵌入它们?
【发布时间】:2021-02-09 14:06:48
【问题描述】:

我有以下 XAML 代码:

<dxm:MapPolygon EnableHighlighting="False">
<dxm:MapPolygon.StrokeStyle>
    <dxm:StrokeStyle Thickness="0"/>
</dxm:MapPolygon.StrokeStyle>
<dxm:MapPolygon.Fill>
    <ImageBrush ImageSource="ShapeFiles\Piran\B010262.tif"/>
</dxm:MapPolygon.Fill>
<dxm:MapPolygon.Points>
    <dxm:GeoPoint Latitude="45.4922488128447995" Longitude="13.6751748869624681" />
    <dxm:GeoPoint Latitude="45.4922488128447995" Longitude="13.7045866089215824" />
    <dxm:GeoPoint Latitude="45.5195646122025437" Longitude="13.7045866089215824" />
    <dxm:GeoPoint Latitude="45.5195646122025437" Longitude="13.6751748869624681" />
</dxm:MapPolygon.Points>
</dxm:MapPolygon>

这用于在发布文件夹中的 .exe 文件旁边生成一个 ShapeFiles/Piran/B010262.tif 文件夹,但现在我得到了system.windows.baml2006.typeconvertermarkupextension 异常。

如果我将文件添加为资源,它们会嵌入到 .exe 文件中,我最终会得到一个 600MB 的 exe,这是我不想要的,因为我希望用户甚至能够更新 .tif 文件没有源代码。

如果我包含完整路径,例如ImageSource="c:\ShapeFiles\Piran\B010262.tif"/&gt;,程序将编译得很好,但我会绑定到那个位置。

如何将文件添加为资源而不将它们嵌入到 exe 文件中?

【问题讨论】:

    标签: wpf visual-studio visual-studio-2019


    【解决方案1】:
    1. 选择要从嵌入中排除的文件。
    2. 属性 > 构建操作:内容
    3. 属性 > 复制到输出目录:始终复制

    另外,请务必在编译前删除 obj\Release 目录,否则文件可能仍会嵌入到 exe 中。

    来源:https://docs.microsoft.com/en-us/dotnet/desktop/wpf/app-development/wpf-application-resource-content-and-data-files?view=netframeworkdesktop-4.8#:~:text=Resource%20Files%3A%20Data%20files%20that,with%20an%20executable%20WPF%20assembly

    【讨论】:

      猜你喜欢
      • 2013-05-10
      • 1970-01-01
      • 2015-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-26
      • 1970-01-01
      相关资源
      最近更新 更多