久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

為什么修改項目輸出目錄會導致:IOException is unh

Why does modifying project output directories cause: IOException was unhandled quot;Cannot locate resource #39;app.xaml#39;.quot;(為什么修改項目輸出目錄會導致:IOException is unhandled quot;Cannot locate resource app.xaml.quot;)
本文介紹了為什么修改項目輸出目錄會導致:IOException is unhandled "Cannot locate resource 'app.xaml'."的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

為了將項目設置合并到 C++ 和 C# 項目的屬性表中,構建了以下屬性表:

In an attempt to consolidate project settings into property sheets for both C++ and C# projects, the following property sheet was constructed:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <!--
      Trying to support both C++ and C# projects by introducing derived 
      properties and setting the appropriate output properties.
  -->
  <PropertyGroup Label="UserMacros">
    <ProjectOrAssemblyName Condition="'$(AssemblyName)'==''">$(ProjectName)</ProjectOrAssemblyName>
    <ProjectOrAssemblyName Condition="'$(ProjectName)'==''">$(AssemblyName)</ProjectOrAssemblyName>
    <ShortPlatform Condition="'$(Platform)'=='Win32'">x86</ShortPlatform>
    <ShortPlatform Condition="'$(Platform)'=='x86'">x86</ShortPlatform>
    <ShortPlatform Condition="'$(Platform)'=='x64'">x64</ShortPlatform>
    <ShortPlatform Condition="'$(Platform)'=='AnyCPU'">AnyCPU</ShortPlatform>
  </PropertyGroup>
  <PropertyGroup>
    <OutputPath>$(OutputRelativePath)/$(ProjectOrAssemblyName)_$(ShortPlatform)_$(Configuration)/</OutputPath>        
    <BaseIntermediateOutputPath>$(OutputRelativePath)/Obj_Exe/$(ProjectOrAssemblyName)_$(ShortPlatform)</BaseIntermediateOutputPath>
    <IntermediateOutputPath>$(BaseIntermediateOutputPath)_$(Configuration)/</IntermediateOutputPath>
    <IntDir>$(IntermediateOutputPath)</IntDir>
    <OutDir>$(OutputPath)</OutDir>
  </PropertyGroup>
</Project>

此屬性表會將所有構建輸出移動到一個單獨的位置OutputRelativePath(在單獨的屬性表中或直接在項目文件中定義)包含源代碼的目錄之外,以便于清理等.但是,在設置后這個構建和構建工作正常,所有單元測試工作正常,很明顯 WPF 可執行項目并不好,因為使用上述屬性表運行應用程序會導致臭名昭著:

This property sheet will move all build output to a separate location OutputRelativePath (defined in separate property sheet or directly in project file) outside directories that contain source code for easier cleanup etc. However, after setting this up and build works fine and all unit tests work fine, it was clear that a WPF executable project was not fine, since running the application with above property sheet results in the infamous:

IOException was unhandled "Cannot locate resource 'app.xaml'."

為什么更改輸出路徑會導致此錯誤?以及如何確定原因是項目構建輸出路徑?這可以在生成的代碼中看到嗎?我找不到?這不是一個錯誤嗎?

Why does changing the output paths result in this error? And how can it be determined that the cause is project build output paths? Can this be seen in generated code? I could not find it? And isn't this a bug?

注意:使用以下屬性表有效,但前提是 IntermediateOutputPath 包含 BaseIntermediateOutputPath.

NOTE: Using the following property sheet works, but only if IntermediateOutputPath contains BaseIntermediateOutputPath.

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <OutputPath>$(OutputRelativePath)/$(AssemblyName)_$(Platform)_$(Configuration)</OutputPath>
    <BaseIntermediateOutputPath>$(OutputRelativePath)/Obj_Exe/$(AssemblyName)_$(Platform)</BaseIntermediateOutputPath>
    <IntermediateOutputPath>$(BaseIntermediateOutputPath)_$(Configuration)</IntermediateOutputPath>
  </PropertyGroup>
</Project>

看來,以某種方式期望輸出路徑包含 AssemblyName 屬性或類似屬性.

So it appears, that somehow it is expected that output paths contain the AssemblyName properties or similar.

另一個程序集中的 XAML 樣式更新:同樣適用于 xaml ResourceDictionary,如果這些 - 例如Brushes.xaml - 位于另一個程序集中,并且該程序集也更改了 OutputPath,這也會引發異常:

UPDATE FOR XAML STYLES IN ANOTHER ASSEMBLY: The same applies to xaml ResourceDictionary if these - e.g. Brushes.xaml - are located in another assembly and this assembly has changed the OutputPath also, this also throws an exception:

XamlParseException was unhandled for set property Source 
with InnerException "Cannot locate resource 'Brushes.xaml'" 

總而言之,輸出位置似乎改變了 xaml 資源名稱,因此無法在運行時以某種方式發現這些資源名稱.奇怪的是它在設計時不是問題......

So all in all it appears output location changes the xaml resource names so these cannot be discovered at runtime, somehow. The odd thing is it is not a problem at design time...

更新:重現異常的最少步驟:

UPDATE: Minimal steps to reproduce the exception:

打開 Visual Studio 2013

Open Visual Studio 2013

創建新的 C# 項目 WPF 應用程序,例如XamlIntermediateOutputPathBug

Create new C# project WPF Application e.g. XamlIntermediateOutputPathBug

卸載項目

編輯項目文件

在第一個 PropertyGroup 之后插入新的 PropertyGroup 為:

After first PropertyGroup insert new PropertyGroup as:

<PropertyGroup>
  <OutputRelativePath>$(ProjectDir)..Build</OutputRelativePath>
  <OutputPath>$(OutputRelativePath)/$(AssemblyName)_$(Platform)_$(Configuration)/</OutputPath>
  <BaseIntermediateOutputPath>$(OutputRelativePath)/Obj_Exe/$(AssemblyName)_$(Platform)</BaseIntermediateOutputPath>
  <IntermediateOutputPath>$(BaseIntermediateOutputPath)_$(Configuration)/</IntermediateOutputPath>
  <IntDir>$(IntermediateOutputPath)</IntDir>
  <OutDir>$(OutputPath)</OutDir>
</PropertyGroup>  

刪除剩余 PropertyGroups 中的 OutputPath 屬性,例如

Delete OutputPath properties in remaining PropertyGroups e.g.

<OutputPath>binDebug</OutputPath>  

和:

<OutputPath>binRelease</OutputPath>  

這應該會在 mainwindow.xaml 的啟動時引發 IOException.這是因為 $(AssemblyName).g.resources 嵌入資源被賦予了以下名稱:

This should then throw an IOException on start for mainwindow.xaml. This is due to the $(AssemblyName).g.resources embedded resource is given the following name:

.mresource public 'Build/Obj_Exe/XamlIntermediateOutputPathBug_AnyCPU_Debug/XamlIntermediateOutputPathBug.g.resources' as Build_Obj_Exe_XamlIntermediateOutputPathBug_AnyCPU_Debug_XamlIntermediateOutputPathBug.g.resources
{
  // Offset: 0x00000000 Length: 0x000003BC
}
.mresource public 'Build/Obj_Exe/XamlIntermediateOutputPathBug_AnyCPU_Debug/XamlIntermediateOutputPathBug.Properties.Resources.resources' as Build_Obj_Exe_XamlIntermediateOutputPathBug_AnyCPU_Debug_XamlIntermediateOutputPathBug.Properties.Resources.resources
{
  // Offset: 0x000003C0 Length: 0x000000B4
}

可以看到 ildasm.exe 并打開程序集的 MANIFEST.還可以看出,正常資源也會以輸出路徑為前綴獲得錯誤的名稱.但是,可以通過在此資源的項目文件中設置 LogicalName 來解決此問題(請參閱 在使用 MSBuild 構建后運行測試時出現 MissingManifestResourceException(.mresource 在清單中有路徑)).對于 xaml 資源,這似乎是不可能的...

as can be seen with ildasm.exe and opening the MANIFEST for the assembly. As can also be seen the normal resources also gets a wrong name with the output path prefixed. This can, however, be fixed by setting the LogicalName in the project file for this resource (see MissingManifestResourceException when running tests after building with MSBuild (.mresource has path in manifest)). This does not appear to be possible for xaml resources...

查看配置后,我注意到我在 OutputPathIntermediateOutputPath 的末尾使用了 /,刪除它們似乎可以工作,見下文:

Having looked at the configuration I noticed I use / at the end of the OutputPath and IntermediateOutputPath, removing these it appears to work, see below:

<PropertyGroup>
  <OutputRelativePath>$(ProjectDir)..Build</OutputRelativePath>
  <OutputPath>$(OutputRelativePath)/$(AssemblyName)_$(Platform)_$(Configuration)</OutputPath>
  <BaseIntermediateOutputPath>$(OutputRelativePath)/Obj_Exe/$(AssemblyName)_$(Platform)</BaseIntermediateOutputPath>
  <IntermediateOutputPath>$(BaseIntermediateOutputPath)_$(Configuration)</IntermediateOutputPath>
  <IntDir>$(IntermediateOutputPath)/</IntDir>
  <OutDir>$(OutputPath)/</OutDir>
</PropertyGroup>  

我覺得這很奇怪......任何關于為什么會這樣或者這是否真的是真的的見解都值得贊賞.請注意,C++ IntDirOutDir 必須有一個尾隨反斜杠,否則您將收到有關此的警告.

I find this rather curious... any insight into why this would be the case or if this is actually true is appreciated. Note that the C++ IntDir and OutDir instead must have a trailing backslash, otherwise you will get warnings about this.

推薦答案

將 MSBuild 輸出詳細程度設置為診斷"很快就揭示了問題的根源:

Setting the MSBuild output verbosity to "Diagnostic" quickly revealed the source of the problem:

1>   (TaskId:21)
1>  Microsoft (R) Build Task 'ResourcesGenerator' Version '4.0.30319.33440 built by: FX45W81RTMREL'. (TaskId:21)
1>  Copyright (C) Microsoft Corporation 2005. All rights reserved. (TaskId:21)
1>  
1>   (TaskId:21)
1>  Generating .resources file: '..Build/Obj_Exe/WpfApplication8_AnyCPU_Debug/WpfApplication8.g.resources'... (TaskId:21)
1>  Reading Resource file: 'C:Usershpass_000ProjectsBuildObj_ExeWpfApplication8_AnyCPU_DebugMainWindow.baml'... (TaskId:21)
1>  Resource ID is 'mainwindow.baml'. (TaskId:21)
1>  Generated .resources file: '..Build/Obj_Exe/WpfApplication8_AnyCPU_Debug/WpfApplication8.g.resources'. 

注意路徑名中正斜杠和反斜杠的混合.Windows 本身知道如何很好地處理路徑名中的正斜杠.但這種能力在其他軟件中往往是缺乏的,它在資源生成器任務中是缺乏的.這需要真正的反斜杠作為路徑分隔符,正斜杠在資源名稱中有效.修復:

Note the mix of forward and backward slashes in the path names. Windows itself knows how to handle forward slashes in path names well. But that capability is often lacking in other software, it is lacking in the resource generator task. Which requires a true backslash as a path separator, a forward slash is valid in a resource name. Fix:

 <OutputPath>$(OutputRelativePath)$(AssemblyName)_$(Platform)_$(Configuration)</OutputPath>
 <BaseIntermediateOutputPath>$(OutputRelativePath)Obj_Exe$(AssemblyName)_$(Platform)</BaseIntermediateOutputPath>
 <IntermediateOutputPath>$(BaseIntermediateOutputPath)_$(Configuration)</IntermediateOutputPath>

換句話說,我只是將 / 替換為 .這解決了問題.

In other words, I simply replaced / with . Which solved the problem.

這篇關于為什么修改項目輸出目錄會導致:IOException is unhandled &quot;Cannot locate resource 'app.xaml'.&quot;的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Is there a C# library that will perform the Excel NORMINV function?(是否有執行 Excel NORMINV 函數的 C# 庫?)
Select x random elements from a weighted list in C# (without replacement)(從 C# 中的加權列表中選擇 x 個隨機元素(無需替換))
Create a summary description of a schedule given a list of shifts(給定輪班列表,創建時間表的摘要描述)
C# Normal Random Number(C# 普通隨機數)
Standard deviation of generic list?(通用列表的標準偏差?)
AsyncCTP: Creating a class that is IAwaitable(AsyncCTP:創建一個 IAwaitable 的類)
主站蜘蛛池模板: 久久91 | 日韩国产欧美一区 | www.99热.com| 日韩精品成人在线 | 99精品欧美一区二区蜜桃免费 | 国产精品99999 | 国产精品99久久久久久www | 成人精品一区二区三区四区 | 精品国产欧美一区二区三区不卡 | hitomi一区二区三区精品 | 日韩精品一区二区三区 | 色爱综合 | 国内精品久久久久久久影视简单 | 国产精品毛片在线 | 亚洲国产片| 日韩欧美中文字幕在线观看 | 久久久综合色 | 一级片网站视频 | 日韩欧美三区 | 久久91| 国产精品一区二 | 99re在线视频观看 | 黄色毛片网站在线观看 | 日本精品一区二区三区在线观看视频 | 精品一二区 | 欧美精品第一区 | 久久99精品久久久久婷婷 | 男女羞羞免费网站 | 日本国产高清 | 国产美女精品视频 | 欧美成年人视频在线观看 | 亚洲人在线 | 中文字幕一区二区三区乱码图片 | 精品视频一区二区三区四区 | 国产欧美精品区一区二区三区 | 久久亚洲精品国产精品紫薇 | 精品96久久久久久中文字幕无 | 在线观看特色大片免费网站 | 久草免费在线视频 | 国产精品视频免费观看 | 久热m3u8 |