2017-12-20 10 views
0

현재 매핑과 관련된 폴더에 XML 매핑 파일에 대한 종속성이있는 써드 파티 DLL을 사용하는 하늘색 함수로 작업하고 있습니다. Azure 스택에서 함수를 게시하고 실행하면 dll이 XML 파일을로드 할 수 없다는 예외가 발생합니다. 나는 bin 디렉토리에 dll과 함께 XML을 가지고 있지만 Azure는 컴파일 된 dll을 필요한 XML없이 임시 폴더로 이동하는 것처럼 보입니다. 다음 예외 메시지를 기반으로 해당 임시 경로를 기준으로 XML을 찾습니다. :dure 파일 종속성을 Azure Function App의 Temp 컴파일 폴더에 복사하는 방법은 무엇입니까?

"Could not find a part of the path 'D:\\local\\Temporary ASP.NET Files\\root\\da2a6178\\25f43073\\assembly\\dl3\\28a13679\\d3614284_4078d301\\Resources\\RepresentationSystem.xml'." 

Azure가 실행중인 임시 폴더에도 이러한 추가 파일을 복사 할 수있는 방법이 있습니까? 양자 택일로, 나는 그것이 단지 temp가 아닌 bin에서 실행되도록 강제 할 수 있습니까?

업데이트 : 불행히도 나는 dll에 대한 정보를 공유 할 수 없습니다. 내가 말할 수있는 것은 모든 것이 내 wwwroot 폴더에 게시되지만 일부 디버그 정보를 출력 할 때 "Temporary ASP.NET Files"폴더에서 실행되고 있음을 알 수 있습니다. 각 dll은 별도의 별도 폴더에 복사됩니다. D : \ local \ Temporary ASP.NET Files \ root \ da2a6178 \ 25f43073 \ assembly \ dl3 \ 28a13679 \ d3614284_4078d301 \ ThirdParty.dll은 문제의 DLL이있는 경로이며, xml이 될 것으로 예상되는 위치와 일치합니다 .

+0

[쿠두 (https://blogs.msdn.microsoft.com/benjaminperkins/2014/03/24/using-kudu-with-windows-azure-web-sites/), 당신이 찾을 수있는 사용 리소스 파일은'D : \ home \ site \ wwwroot'에 있습니다. 그리고 함수 실행 디렉토리는 하늘에 배포 한 컨텐츠 디렉토리와 다릅니다. 그리고 그것은'D : \ Program Files (x86) \ SiteExtensions \ Functions \ 1.0.11388 \'과 같이 보일 것입니다. 질문을 업데이트하고 xml 파일을 읽는 방법을 찾기 위해 타사 DLL에 대한 자세한 정보를 제공하는 것이 좋습니다. 가능하면 xml 파일을 읽는 데 절대 경로를 사용할 수 있습니다. –

+0

[ILSpy] (https://github.com/icsharpcode/ILSpy#ilspy-------)를 사용하여 타사 DLL에서 xml 파일을 읽는 코드를 직접 확인하여이 문제를 좁힐 수 있습니다. 또한 하늘빛 기능이 예상대로 작동합니까? –

답변

1

이 문제에 대한 진정한 대답은 아니지만이 문제의 해결 방법은 dll 함수가 실행되기 전에 코드에 함수가 있어야하고 Temporary ASP.Net 폴더에있는 해당 DLL을 검색하는 것입니다. 그런 다음 xml 파일을 알려진 위치에서 해당 디렉토리로 복사합니다.

// Work Around Begin Here 
string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); 
// Check if we are in temp dir 
if (assemblyFolder.Contains("Temporary ASP.NET Files")) 
{ 
    DirectoryInfo dir = new DirectoryInfo(assemblyFolder); 
    // Go up 2 dirs 
    DirectoryInfo top = dir.Parent.Parent; 
    DirectoryInfo[] dirs = top.GetDirectories(); 
    foreach (DirectoryInfo child in dirs) 
    { 
     DirectoryInfo[] dirs2 = child.GetDirectories(); 
     foreach (DirectoryInfo child2 in dirs2) 
     { 
      // Find out if this is the Rep 
      if (File.Exists(child2.FullName + "\\ThirdParty.Representation.dll")) 
      { 

       // Look to see if resource folder is there 
       if (!Directory.Exists(child2.FullName + "\\Resources")) 
       { 
         child2.CreateSubdirectory("Resources"); 
       } 

       DirectoryInfo resDir = new DirectoryInfo(child2.FullName + "\\Resources"); 

       if (File.Exists(resourceDir + "RepresentationSystem.xml")) 
       { 
        if(!File.Exists(resDir.FullName + "\\RepresentationSystem.xml")) 
        { 

         File.Copy(resourceDir + "RepresentationSystem.xml", resDir.FullName + "\\RepresentationSystem.xml"); 
        } 
       } 

       if (File.Exists(resourceDir + "UnitSystem.xml")) 
       { 
        if (!File.Exists(resDir.FullName + "\\UnitSystem.xml")) 
        { 

         File.Copy(resourceDir + "UnitSystem.xml", resDir.FullName + "\\UnitSystem.xml"); 
        } 
       } 
      } 
     } 
    } 
} 
0

이 해결 방법은 DoubleHolo에게 감사드립니다. 잘 돌아갑니다. 코드를 간단하게하기 위해 Path.Combine 만 추가하여 코드를 변경했습니다.

private void CopyResourcesToTemporaryFolder() 
{ 
     // Work Around Begin Here 
     string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); 

     string resourceDir = Path.Combine(FileUtils.WebProjectFolder, "Resources"); 

     // Check if we are in temp dir 
     if (assemblyFolder.Contains("Temporary ASP.NET Files")) 
     { 
      DirectoryInfo dir = new DirectoryInfo(assemblyFolder); 
      // Go up 2 dirs 
      DirectoryInfo top = dir.Parent.Parent; 
      DirectoryInfo[] dirs = top.GetDirectories(); 
      foreach (DirectoryInfo child in dirs) 
      { 
       DirectoryInfo[] dirs2 = child.GetDirectories(); 
       foreach (DirectoryInfo child2 in dirs2) 
       { 
        // Find out if this is the Rep 
        if (File.Exists(Path.Combine(child2.FullName, "AgGateway.ADAPT.Representation.DLL"))) 
        { 

         // Look to see if resource folder is there 
         if (!Directory.Exists(Path.Combine(child2.FullName, "Resources"))) 
         { 
          child2.CreateSubdirectory("Resources"); 
         } 

         DirectoryInfo resDir = new DirectoryInfo(Path.Combine(child2.FullName, "Resources")); 

         if (File.Exists(Path.Combine(resourceDir, "RepresentationSystem.xml"))) 
         { 
          if (!File.Exists(Path.Combine(resDir.FullName, "RepresentationSystem.xml"))) 
          { 

           File.Copy(Path.Combine(resourceDir, "RepresentationSystem.xml"), Path.Combine(resDir.FullName, "RepresentationSystem.xml")); 
          } 
         } 

         if (File.Exists(Path.Combine(resourceDir, "UnitSystem.xml"))) 
         { 
          if (!File.Exists(Path.Combine(resDir.FullName, "UnitSystem.xml"))) 
          { 

           File.Copy(Path.Combine(resourceDir, "UnitSystem.xml"), Path.Combine(resDir.FullName, "UnitSystem.xml")); 
          } 
         } 

        } 
       } 
      } 
     } 

    }