简体   繁体   English

Azure 云服务使用与其辅助角色不同的 nuget 包路径

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

I have a .net47 azure cloudservice referencing my .netstandard libraries.我有一个 .net47 azure 云服务引用我的 .netstandard 库。

those libraries use System.Data.SqlClient and System.Reflection.TypeExtesions which I included to my worker role with nuget.这些库使用System.Data.SqlClientSystem.Reflection.TypeExtesions ,我使用 nuget 将它们包含在我的辅助角色中。

for some reason I am getting a BadImageFormatException - after a quick search I found out that the approot folder of the cloudservice contains a different version of System.Data.SqlClient.dll and System.Reflection.TypeExtesions.dll than the bin/debug folder of the WorkerRole project (The size is different, also using a powershell script I was able to load the latter but not the first -- same BadImageFormatException).由于某种原因,我得到一个BadImageFormatException -快速搜索,我发现后,该approot的cloudservice的文件夹中包含了不同版本的System.Data.SqlClient.dllSystem.Reflection.TypeExtesions.dllbin/debug的文件夹WorkerRole 项目(大小不同,也使用了 powershell 脚本,我能够加载后者但不能加载第一个——同样的 BadImageFormatException)。

copying the dlls from bin/debug to the approot fixes the issue - but this isn't a good fix.将 dll 从 bin/debug 复制到 approot 解决了这个问题 - 但这不是一个好的解决方法。

I have no idea what could cause this version mismatch - since it seems to me that the cloudservice would just copy the dlls from bin/debug我不知道什么可能导致此版本不匹配 - 因为在我看来,云服务只会从 bin/debug 复制 dll

**both projects are compiled and released in debug for the time being **两个项目暂时都在debug中编译发布

Update更新

I was able to figure out that the cloud service, and the worker role class library are taking the nuget dll from two different paths where the first one doesn't work -我能够弄清楚云服务和辅助角色类库正在从两个不同的路径获取 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

deleting .nuget folder doesn't resolve this issue - seems like some weird configuration issue that causes the cloud service to be resolved with a different package than the csproj itself删除 .nuget 文件夹不能解决这个问题 - 似乎是一些奇怪的配置问题,导致云服务使用与 csproj 本身不同的包来解决

We ran into this same issue as well but only on projects using the Worker role, not projects using the Web role.我们也遇到了同样的问题,但仅限于使用 Worker 角色的项目,而不是使用 Web 角色的项目。 The Web role cloud service project on build copies the source web project bin directory to the cloud service project bin directory.构建时的 Web 角色云服务项目将源 Web 项目 bin 目录复制到云服务项目 bin 目录。

We emulated the copying of the source project bin directory to the cloud service bin directory and found that to work.我们模拟了将源项目 bin 目录复制到云服务 bin 目录,发现可以。 To do this we added a AfterBuild Msbuild step in the Cloud Service ccproj file to do the copying.为此,我们在云服务 ccproj 文件中添加了 AfterBuild Msbuild 步骤来进行复制。

A better work around was posted here : https://github.com/Azure/azure-sdk-for-net/issues/3699#issuecomment-612306965这里发布了一个更好的解决方法https : //github.com/Azure/azure-sdk-for-net/issues/3699#issuecomment-612306965

This should be added to your source project csproj file:这应该添加到您的源项目 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