【问题标题】:Azure git deployment - missing references in 2nd assemblyAzure git 部署 - 第二个程序集中缺少引用
【发布时间】:2012-11-05 23:05:30
【问题描述】:

我正在尝试将 Bitbucket 部署设置到 Azure 网站。我成功链接了 Bitbucket 和 Azure,但是当我推送到 Bitbucket 时,我在 Azure 站点上收到以下错误:

如果我点击“查看日志”,它会显示以下编译错误:

    D:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1578,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [C:\DWASFiles\Sites\<projname>\VirtualDirectory0\site\repository\<projname>.Common\<projname>.Common.csproj]
    D:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1578,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "WebMatrix.WebData, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [C:\DWASFiles\Sites\<projname>\VirtualDirectory0\site\repository\<projname>.Common\<projname>.Common.csproj]
    CustomMembershipProvider.cs(5,7): error CS0246: The type or namespace name 'WebMatrix' could not be found (are you missing a using directive or an assembly reference?) [C:\DWASFiles\Sites\<projname>\VirtualDirectory0\site\repository\<projname>.Common\<projname>.Common.csproj]
    CustomMembershipProvider.cs(9,38): error CS0246: The type or namespace name 'ExtendedMembershipProvider' could not be found (are you missing a using directive or an assembly reference?) [C:\DWASFiles\Sites\<projname>\VirtualDirectory0\site\repository\<projname>.Common\<projname>.Common.csproj]
    Models\AccountModels.cs(3,18): error CS0234: The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) [C:\DWASFiles\Sites\<projname>\VirtualDirectory0\site\repository\<projname>.Common\<projname>.Common.csproj]
    CustomMembershipProvider.cs(198,37): error CS0246: The type or namespace name 'OAuthAccountData' could not be found (are you missing a using directive or an assembly reference?) [C:\DWASFiles\Sites\<projname>\VirtualDirectory0\site\repository\<projname>.Common\<projname>.Common.csproj]
    Models\AccountModels.cs(40,10): error CS0246: The type or namespace name 'Compare' could not be found (are you missing a using directive or an assembly reference?) [C:\DWASFiles\Sites\<projname>\VirtualDirectory0\site\repository\<projname>.Common\<projname>.Common.csproj]
    Models\AccountModels.cs(40,10): error CS0246: The type or namespace name 'CompareAttribute' could not be found (are you missing a using directive or an assembly reference?) [C:\DWASFiles\Sites\<projname>\VirtualDirectory0\site\repository\<projname>.Common\<projname>.Common.csproj]
    Models\AccountModels.cs(73,10): error CS0246: The type or namespace name 'Compare' could not be found (are you missing a using directive or an assembly reference?) [C:\DWASFiles\Sites\<projname>\VirtualDirectory0\site\repository\<projname>.Common\<projname>.Common.csproj]
    Models\AccountModels.cs(73,10): error CS0246: The type or namespace name 'CompareAttribute' could not be found (are you missing a using directive or an assembly reference?) [C:\DWASFiles\Sites\<projname>\VirtualDirectory0\site\repository\<projname>.Common\<projname>.Common.csproj]

请注意,这些编译错误针对我项目中的另一个程序集(我放置业务逻辑的程序集)。

在谷歌搜索时,我发现的唯一提及是必须将这些引用的“本地副本”标志设置为 true。我已经尝试过了,但仍然遇到同样的错误。

这一切都在本地编译得很好。有什么想法吗?

更新

添加更多信息,我在 Git 存储库中的项目结构如下:

+ProjName
    ProjName.csproj
    web.config
    ...etc...
+ProjName.Common
    ProjName.Common.csproj
+ProjName.Tests
    ProjName.Tests.csproj
+packages <-- these are Nuget packages
ProjName.sln

Azure 显示的编译错误表明失败的是 ProjName.vcproj - 但它们引用了 ProjName.Common 程序集参考。

请注意,此布局是 VisualStudio 创建的(即 webroot 的额外项目子目录)。

我不太确定 Azure 在进行 Git 部署时会做什么。它是否识别 ProjName 目录是 webroot,并解析 ProjName.sln 编译解决方案中的任何其他程序集(与 Visual Studio 相同)?

另外,我没有向 Git 添加任何“bin”文件夹。但是,我只是将其作为测试进行了尝试,它并没有改变 Azure 产生的编译错误。

【问题讨论】:

  • 检查this solution。 FTP 是一款出色的 Windows Azure 网站调试工具。
  • 也许我误解了 git repo 中需要哪些文件。我没有将我的 bin 文件夹签入 git(我认为 Azure 以与 VS 在本地编译时相同的方式生成它?)。当我 FTP 进入时,.Common(这是我的业务逻辑程序集)有一个空的 bin 文件夹(可能是因为它无法编译)。而作为我的 web 根目录的文件夹根本没有 bin 目录(可能是因为编译失败的 .Common 是必需的依赖项)。
  • @丹。这取决于。您是否使用任何不在普通 Windows 安装中的 dll,您需要提供它们。您在设置时是否遵循本指南? windowsazure.com/en-us/develop/net/common-tasks/…
  • @MagnusKarlsson 我没有使用任何不在 nuget "packages" 目录中的东西,或者解决方案中包含的 .Common 项目(所以我认为 Azure 会编译它)。

标签: asp.net-mvc git deployment azure web-deployment


【解决方案1】:

2012 年 11 月 25 日更新:查看 Dan 的 repo 后,问题是库项目使用 GAC 中的 Mvc 4 而不是使用 NuGet 包。切换到 NuGet 包使其在 Azure 上运行良好。

理论上,MVC4 可以在 Azure 机器上的 GAC 中,这不是问题。也许他们会在某个时候到达那里。虽然一般来说,MVC 团队越来越多地推动基于 NuGet 的模型,在这种模型中您不依赖 GAC 中的内容。

原答案:

一般来说,您应该避免将二进制文件提交到您的 git 存储库,而是依靠 NuGet 来检索它们。请参阅 https://github.com/KuduApps/Mvc4ApplicationFx40WithLib 了解在 Azure 网站中执行此操作并正常工作的示例项目。

但根据您的项目结构,我看到您的项目似乎使用 C++ (.vcproj)。如果是这样,那么可能的问题是今天通过 git 发布时,Azure 网站可能不支持 C++。到目前为止,我不认为人们必须使用 C# 和 VB。如果这确实是问题,那么我建议您在https://github.com/projectkudu/kudu 上打开一个问题,以便我们可以正确跟踪。

【讨论】:

  • 抱歉,我不小心在问题中输入了 .vcproj (我来自 C++ 背景,所以这是我的手自动输入的内容!)。扩展名实际上是 .csproj。我会更新我的问题。
  • 我看不到任何与我的布局不同的 kudo 项目。我们在解决方案中都有额外的项目以及 MVC webroot 部分,并且不包含 bin 文件。如果 Azure 在您推送更改时自动为您编译,那么至少我知道我这样做的方式没有根本性的问题。
  • 如果你能分享一个有问题的 repo(例如在 GitHub 上),我可以看一下,也许可以解决。如果你有私人的东西,它不一定是你的完整回购。任何足以表明问题的东西都可以。
  • 大卫 - 我可以吻你。我将我的 MVC 模型移到了他们自己的项目中,其中一个模型使用了 MVC 类型,因此 resharper 添加了 GAC 参考。 Git>Azure 然后抛出了一个不稳定的部署。多亏了你,我删除了 mvc .dll 并通过 Nuget 应用了 MVC,现在一切都很好。 x1000 谢谢-我的周末得救了
【解决方案2】:

所以我的 .Common 程序集引用了 System.Web.Mvc 和 WebMatrix.WebData,看起来 Azure 不支持。我有一些成员代码,它们在公共程序集中而不是 Web 项目中使用这些引用。删除那些,删除错误。我将不得不稍微重构代码,以便公共库不需要这些引用。

【讨论】:

  • 是我的评论导致您这样做的吗?我会喜欢赏金,因为无论如何你都会失去它:)
  • 老实说,更多的是大卫关于创建一个演示问题的测试项目的评论。我试过这个,但我的测试项目运行良好。因此,我再次查看了我的项目,它打破了它,并通过反复试验来解决它。如果您回答自己的问题,就会失去赏金,这似乎有点愚蠢。
  • 哎呀!在赏金问题上,我想可能有人在让 SO 用户帮助他们之后保留了他们的赏金,这导致了这个“新”系统,你将永远失去你的赏金。
  • 很高兴你知道了。看到一个小复制仍然会很有趣,所以我们可以深入了解它。通常,如果它是在您的机器上构建的,那么理想情况下它也应该在 Azure 上构建。
  • 我创建了一个测试项目来显示这个问题。请注意,我必须同时添加对 system.web.mvc 的引用,并且还要使用它(请参阅我的上一次提交,其中我刚刚创建了 AjaxHelper 类的虚拟实例)。如果没有这种用法,它不会显示错误 - 我认为引用已被优化,因为它没有被使用。回购在这里:bitbucket.org/dracan/azuretest。请注意,这会在本地编译文件。
【解决方案3】:

我今天在 azure 训练营遇到了这个问题。

在解决方案上启用 Nuget 包还原并将这些更改提交到 github 存储库可成功部署

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-17
    • 2019-10-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多