簡體   English   中英

Azure 雲服務使用與其輔助角色不同的 nuget 包路徑

[英]Azure Cloud Service uses a different nuget package path than its worker role

我有一個 .net47 azure 雲服務引用我的 .netstandard 庫。

這些庫使用System.Data.SqlClientSystem.Reflection.TypeExtesions ,我使用 nuget 將它們包含在我的輔助角色中。

由於某種原因,我得到一個BadImageFormatException -快速搜索,我發現后,該approot的cloudservice的文件夾中包含了不同版本的System.Data.SqlClient.dllSystem.Reflection.TypeExtesions.dllbin/debug的文件夾WorkerRole 項目(大小不同,也使用了 powershell 腳本,我能夠加載后者但不能加載第一個——同樣的 BadImageFormatException)。

將 dll 從 bin/debug 復制到 approot 解決了這個問題 - 但這不是一個好的解決方法。

我不知道什么可能導致此版本不匹配 - 因為在我看來,雲服務只會從 bin/debug 復制 dll

**兩個項目暫時都在debug中編譯發布

更新

我能夠弄清楚雲服務和輔助角色類庫正在從兩個不同的路徑獲取 nuget dll,而第一個路徑不起作用 -

%userprofile%\.nuget\packages\System.Data.SqlClient\4.4.0\ref\net461\System.Data.SqlClient.dll
%userprofile%\.nuget\packages\System.Data.SqlClient\4.4.0\runtimes\win\lib\net461\System.Data.SqlClient.dll

刪除 .nuget 文件夾不能解決這個問題 - 似乎是一些奇怪的配置問題,導致雲服務使用與 csproj 本身不同的包來解決

我們也遇到了同樣的問題,但僅限於使用 Worker 角色的項目,而不是使用 Web 角色的項目。 構建時的 Web 角色雲服務項目將源 Web 項目 bin 目錄復制到雲服務項目 bin 目錄。

我們模擬了將源項目 bin 目錄復制到雲服務 bin 目錄,發現可以。 為此,我們在雲服務 ccproj 文件中添加了 AfterBuild Msbuild 步驟來進行復制。

這里發布了一個更好的解決方法https : //github.com/Azure/azure-sdk-for-net/issues/3699#issuecomment-612306965

這應該添加到您的源項目 csproj 文件中:

 <Target 
     Name="BuiltProjectOutputGroupDependencies" 
     DependsOnTargets="$(BuiltProjectOutputGroupDependenciesDependsOn)"
     Returns="@(BuiltProjectOutputGroupDependency)">
    <ItemGroup>
      <BuiltProjectOutputGroupDependency Include="@(ReferenceCopyLocalPaths->'%(FullPath)');
                                                  @(ReferenceDependencyPaths->'%(FullPath)');
                                                  @(NativeReferenceFile->'%(FullPath)');
                                                  @(_DeploymentLooseManifestFile->'%(FullPath)');
                                                  @(ResolvedIsolatedComModules->'%(FullPath)')"/>
    </ItemGroup>
  </Target>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM