【问题标题】:Azure Cloud Service uses a different nuget package path than its worker roleAzure 云服务使用与其辅助角色不同的 nuget 包路径
【发布时间】:2020-04-15 02:10:20
【问题描述】:

我有一个引用我的 .netstandard 库的 .net47 azure 云服务。

这些库使用 System.Data.SqlClientSystem.Reflection.TypeExtesions,我将它们包含在我的 nuget 工作角色中。

由于某种原因,我得到了 BadImageFormatException - 经过快速搜索后,我发现 cloudservice 的 approot 文件夹包含的 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 本身不同的包来解决云服务

【问题讨论】:

    标签: c# azure nuget azure-cloud-services


    【解决方案1】:

    我们也遇到了同样的问题,但仅限于使用 Worker 角色的项目,而不是使用 Web 角色的项目。构建时的Web角色云服务项目将源Web项目bin目录复制到云服务项目bin目录。

    我们模拟了将源项目bin目录复制到云服务bin目录,发现可以。为此,我们在 Cloud Service 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>
    

    【讨论】:

      猜你喜欢
      • 2014-09-19
      • 2015-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-14
      • 1970-01-01
      • 2016-04-04
      相关资源
      最近更新 更多