错误CS0012:类型...在未引用的程序集中定义。您必须添加对程序集 'mscorlib, Version=2.0.5.0 的引用

发布于 2025-01-17 04:13:11 字数 7922 浏览 2 评论 0原文

当我使用我的 StackExchange.Precompilation 分支构建代码时出现此错误 - https://github.com /MarkKharitonov/StackExchange.Precompilation

所以我接受了它(遵循https://stackoverflow.com/a/71611526/80002),将其调整为与最新版本的软件包配合使用它运行良好:

C:\work\StackExchange.Precompilation [master ≡]> git lg -4
e9055ed |  (HEAD -> master, origin/master, origin/HEAD) Enable convenient debugging of the precompiler. (6 minutes ago) [Kharitonov, Mark] (2022-03-26 20:04:24 -0400)
7568de6 |  Minor changes, #define SE_PRECOMPILER_INCLUDE_RAZOR automatically when necessary. (4 hours ago) [Kharitonov, Mark] (2022-03-26 15:44:05 -0400)
50349c3 |  Update the code to use the most recent packages. (7 hours ago) [Kharitonov, Mark] (2022-03-25 20:01:26 -0400)
d595fac |  sourcelink it is (3 years, 3 months ago) [sprelog] (2018-12-14 14:41:05 +0100)
C:\work\StackExchange.Precompilation [master ≡]> .\BuildAndPack.ps1 -Debug
  Determining projects to restore...
  Restored C:\work\StackExchange.Precompilation\StackExchange.Precompilation.Tests\StackExchange.Precompilation.Tests.csproj (in 592 ms).
  Restored C:\work\StackExchange.Precompilation\Test.Module\Test.Module.csproj (in 592 ms).
  Restored C:\work\StackExchange.Precompilation\Test.ConsoleApp\Test.ConsoleApp.csproj (in 592 ms).
  Restored C:\work\StackExchange.Precompilation\Test.WebApp.ExternalViews\Test.WebApp.ExternalViews.csproj (in 592 ms).
  Restored C:\work\StackExchange.Precompilation\StackExhcange.Precompilation.MVC5\StackExchange.Precompilation.MVC5.csproj (in 592 ms).
  Restored C:\work\StackExchange.Precompilation\Test.WebApp\Test.WebApp.csproj (in 592 ms).
  Restored C:\work\StackExchange.Precompilation\StackExchange.Precompilation\StackExchange.Precompilation.csproj (in 592 ms).
  Restored C:\work\StackExchange.Precompilation\StackExchange.Precompilation.Build\StackExchange.Precompilation.Build.csproj (in 592 ms).
  StackExchange.Precompilation -> C:\work\StackExchange.Precompilation\StackExchange.Precompilation\bin\Debug\net472\StackExchange.Precompilation.dll
  StackExchange.Precompilation.Build -> C:\work\StackExchange.Precompilation\StackExchange.Precompilation.Build\bin\Debug\net472\StackExchange.Precompiler.exe
  Test.Module -> C:\work\StackExchange.Precompilation\Test.Module\bin\Debug\net472\Test.Module.dll
  StackExchange.Precompilation.MVC5 -> C:\work\StackExchange.Precompilation\StackExhcange.Precompilation.MVC5\bin\Debug\net472\StackExchange.Precompilation.MVC5.dll
  Test.ConsoleApp -> C:\work\StackExchange.Precompilation\Test.ConsoleApp\bin\Debug\net472\Test.ConsoleApp.exe
  Test.WebApp.ExternalViews -> C:\work\StackExchange.Precompilation\Test.WebApp.ExternalViews\bin\Debug\net472\Test.WebApp.ExternalViews.dll
  Test.WebApp -> C:\work\StackExchange.Precompilation\Test.WebApp\bin\Test.WebApp.dll
  StackExchange.Precompilation.Tests -> C:\work\StackExchange.Precompilation\StackExchange.Precompilation.Tests\bin\Debug\net472\StackExchange.Precompilation.Tests.dll
  Successfully created package 'C:\work\StackExchange.Precompilation\packages\obj\StackExchange.Precompilation.Build.6.1.0-local1648325439.nupkg'.
  Successfully created package 'C:\work\StackExchange.Precompilation\packages\obj\StackExchange.Precompilation.6.1.0-local1648325439.nupkg'.
  Successfully created package 'C:\work\StackExchange.Precompilation\packages\obj\StackExchange.Precompilation.MVC5.6.1.0-local1648325439.nupkg'.
C:\work\StackExchange.Precompilation\Test.ConsoleApp\Program.cs
C:\work\StackExchange.Precompilation\Test.ConsoleApp\Program.cs
Test.ConsoleApp.AliasTest
C:\work\StackExchange.Precompilation [master ≡]>

我对 Test.WebApp 做了一个小更改,但现在失败了:

C:\work\StackExchange.Precompilation [master ≡]> git co WithCommonLogging
Switched to branch 'WithCommonLogging'
Your branch is up to date with 'origin/WithCommonLogging'.
C:\work\StackExchange.Precompilation [WithCommonLogging ≡]> git lg -2
13a2c5f |  (HEAD -> WithCommonLogging, origin/WithCommonLogging) Add a test case involving Common.Logging, which depends on mscorlib 2.0.5.0 - currently breaks the build. (8 minutes ago) [Kharitonov, Mark] (2022-03-26 20:05:26 -0400)
e9055ed |  (origin/master, origin/HEAD, master) Enable convenient debugging of the precompiler. (9 minutes ago) [Kharitonov, Mark] (2022-03-26 20:04:24 -0400)
C:\work\StackExchange.Precompilation [WithCommonLogging ≡]> .\BuildAndPack.ps1 -Debug
  Determining projects to restore...
  Restored C:\work\StackExchange.Precompilation\StackExchange.Precompilation\StackExchange.Precompilation.csproj (in 585 ms).
  Restored C:\work\StackExchange.Precompilation\StackExchange.Precompilation.Tests\StackExchange.Precompilation.Tests.csproj (in 586 ms).
  Restored C:\work\StackExchange.Precompilation\Test.ConsoleApp\Test.ConsoleApp.csproj (in 586 ms).
  Restored C:\work\StackExchange.Precompilation\StackExhcange.Precompilation.MVC5\StackExchange.Precompilation.MVC5.csproj (in 586 ms).
  Restored C:\work\StackExchange.Precompilation\Test.WebApp\Test.WebApp.csproj (in 586 ms).
  Restored C:\work\StackExchange.Precompilation\Test.Module\Test.Module.csproj (in 586 ms).
  Restored C:\work\StackExchange.Precompilation\StackExchange.Precompilation.Build\StackExchange.Precompilation.Build.csproj (in 586 ms).
  Restored C:\work\StackExchange.Precompilation\Test.WebApp.ExternalViews\Test.WebApp.ExternalViews.csproj (in 585 ms).
  StackExchange.Precompilation -> C:\work\StackExchange.Precompilation\StackExchange.Precompilation\bin\Debug\net472\StackExchange.Precompilation.dll
  StackExchange.Precompilation.Build -> C:\work\StackExchange.Precompilation\StackExchange.Precompilation.Build\bin\Debug\net472\StackExchange.Precompiler.exe
  Test.Module -> C:\work\StackExchange.Precompilation\Test.Module\bin\Debug\net472\Test.Module.dll
  StackExchange.Precompilation.MVC5 -> C:\work\StackExchange.Precompilation\StackExhcange.Precompilation.MVC5\bin\Debug\net472\StackExchange.Precompilation.MVC5.dll
  Test.ConsoleApp -> C:\work\StackExchange.Precompilation\Test.ConsoleApp\bin\Debug\net472\Test.ConsoleApp.exe
  Test.WebApp.ExternalViews -> C:\work\StackExchange.Precompilation\Test.WebApp.ExternalViews\bin\Debug\net472\Test.WebApp.ExternalViews.dll
C:\work\StackExchange.Precompilation\Test.WebApp\MvcApplication.cs(29,13): error CS0012: The type 'Action<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes'. [C:\work\StackExchange.Precompilation\Test.WebApp\Test.WebApp.csproj]
  StackExchange.Precompilation.Tests -> C:\work\StackExchange.Precompilation\StackExchange.Precompilation.Tests\bin\Debug\net472\StackExchange.Precompilation.Tests.dll
MSBuild failed

更改是:

  1. 将 NuGet 引用添加到 Common.Logging
  2. 调用 ILog.Info

https://github.com/MarkKharitonov/StackExchange.Precompilation/commit/13a2c5f4a27915307d0a403d1c73f0922da87ebe

现在它失败并显示错误消息

C:\work\StackExchange.Precompilation\Test.WebApp\MvcApplication.cs(29,13): error CS0012: The type 'Action<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes'. [C:\work\StackExchange.Precompilation\Test.WebApp\Test.WebApp.csproj]

现在我明白 StackExchange.Precompilation 复制了以下逻辑7 年前的 csc.exe 代码。不幸的是,到目前为止,它是我必须替换 aspnet_compiler.exe 的最佳选择。

所以我的问题很简单 - 我们如何解决它?

I get this error when I build the code using my fork of StackExchange.Precompilation - https://github.com/MarkKharitonov/StackExchange.Precompilation

So I took it (following the advice in https://stackoverflow.com/a/71611526/80002), adjusted it to work with the most recent versions of the packages and it works well:

C:\work\StackExchange.Precompilation [master ≡]> git lg -4
e9055ed |  (HEAD -> master, origin/master, origin/HEAD) Enable convenient debugging of the precompiler. (6 minutes ago) [Kharitonov, Mark] (2022-03-26 20:04:24 -0400)
7568de6 |  Minor changes, #define SE_PRECOMPILER_INCLUDE_RAZOR automatically when necessary. (4 hours ago) [Kharitonov, Mark] (2022-03-26 15:44:05 -0400)
50349c3 |  Update the code to use the most recent packages. (7 hours ago) [Kharitonov, Mark] (2022-03-25 20:01:26 -0400)
d595fac |  sourcelink it is (3 years, 3 months ago) [sprelog] (2018-12-14 14:41:05 +0100)
C:\work\StackExchange.Precompilation [master ≡]> .\BuildAndPack.ps1 -Debug
  Determining projects to restore...
  Restored C:\work\StackExchange.Precompilation\StackExchange.Precompilation.Tests\StackExchange.Precompilation.Tests.csproj (in 592 ms).
  Restored C:\work\StackExchange.Precompilation\Test.Module\Test.Module.csproj (in 592 ms).
  Restored C:\work\StackExchange.Precompilation\Test.ConsoleApp\Test.ConsoleApp.csproj (in 592 ms).
  Restored C:\work\StackExchange.Precompilation\Test.WebApp.ExternalViews\Test.WebApp.ExternalViews.csproj (in 592 ms).
  Restored C:\work\StackExchange.Precompilation\StackExhcange.Precompilation.MVC5\StackExchange.Precompilation.MVC5.csproj (in 592 ms).
  Restored C:\work\StackExchange.Precompilation\Test.WebApp\Test.WebApp.csproj (in 592 ms).
  Restored C:\work\StackExchange.Precompilation\StackExchange.Precompilation\StackExchange.Precompilation.csproj (in 592 ms).
  Restored C:\work\StackExchange.Precompilation\StackExchange.Precompilation.Build\StackExchange.Precompilation.Build.csproj (in 592 ms).
  StackExchange.Precompilation -> C:\work\StackExchange.Precompilation\StackExchange.Precompilation\bin\Debug\net472\StackExchange.Precompilation.dll
  StackExchange.Precompilation.Build -> C:\work\StackExchange.Precompilation\StackExchange.Precompilation.Build\bin\Debug\net472\StackExchange.Precompiler.exe
  Test.Module -> C:\work\StackExchange.Precompilation\Test.Module\bin\Debug\net472\Test.Module.dll
  StackExchange.Precompilation.MVC5 -> C:\work\StackExchange.Precompilation\StackExhcange.Precompilation.MVC5\bin\Debug\net472\StackExchange.Precompilation.MVC5.dll
  Test.ConsoleApp -> C:\work\StackExchange.Precompilation\Test.ConsoleApp\bin\Debug\net472\Test.ConsoleApp.exe
  Test.WebApp.ExternalViews -> C:\work\StackExchange.Precompilation\Test.WebApp.ExternalViews\bin\Debug\net472\Test.WebApp.ExternalViews.dll
  Test.WebApp -> C:\work\StackExchange.Precompilation\Test.WebApp\bin\Test.WebApp.dll
  StackExchange.Precompilation.Tests -> C:\work\StackExchange.Precompilation\StackExchange.Precompilation.Tests\bin\Debug\net472\StackExchange.Precompilation.Tests.dll
  Successfully created package 'C:\work\StackExchange.Precompilation\packages\obj\StackExchange.Precompilation.Build.6.1.0-local1648325439.nupkg'.
  Successfully created package 'C:\work\StackExchange.Precompilation\packages\obj\StackExchange.Precompilation.6.1.0-local1648325439.nupkg'.
  Successfully created package 'C:\work\StackExchange.Precompilation\packages\obj\StackExchange.Precompilation.MVC5.6.1.0-local1648325439.nupkg'.
C:\work\StackExchange.Precompilation\Test.ConsoleApp\Program.cs
C:\work\StackExchange.Precompilation\Test.ConsoleApp\Program.cs
Test.ConsoleApp.AliasTest
C:\work\StackExchange.Precompilation [master ≡]>

I made a small change to Test.WebApp and now it fails:

C:\work\StackExchange.Precompilation [master ≡]> git co WithCommonLogging
Switched to branch 'WithCommonLogging'
Your branch is up to date with 'origin/WithCommonLogging'.
C:\work\StackExchange.Precompilation [WithCommonLogging ≡]> git lg -2
13a2c5f |  (HEAD -> WithCommonLogging, origin/WithCommonLogging) Add a test case involving Common.Logging, which depends on mscorlib 2.0.5.0 - currently breaks the build. (8 minutes ago) [Kharitonov, Mark] (2022-03-26 20:05:26 -0400)
e9055ed |  (origin/master, origin/HEAD, master) Enable convenient debugging of the precompiler. (9 minutes ago) [Kharitonov, Mark] (2022-03-26 20:04:24 -0400)
C:\work\StackExchange.Precompilation [WithCommonLogging ≡]> .\BuildAndPack.ps1 -Debug
  Determining projects to restore...
  Restored C:\work\StackExchange.Precompilation\StackExchange.Precompilation\StackExchange.Precompilation.csproj (in 585 ms).
  Restored C:\work\StackExchange.Precompilation\StackExchange.Precompilation.Tests\StackExchange.Precompilation.Tests.csproj (in 586 ms).
  Restored C:\work\StackExchange.Precompilation\Test.ConsoleApp\Test.ConsoleApp.csproj (in 586 ms).
  Restored C:\work\StackExchange.Precompilation\StackExhcange.Precompilation.MVC5\StackExchange.Precompilation.MVC5.csproj (in 586 ms).
  Restored C:\work\StackExchange.Precompilation\Test.WebApp\Test.WebApp.csproj (in 586 ms).
  Restored C:\work\StackExchange.Precompilation\Test.Module\Test.Module.csproj (in 586 ms).
  Restored C:\work\StackExchange.Precompilation\StackExchange.Precompilation.Build\StackExchange.Precompilation.Build.csproj (in 586 ms).
  Restored C:\work\StackExchange.Precompilation\Test.WebApp.ExternalViews\Test.WebApp.ExternalViews.csproj (in 585 ms).
  StackExchange.Precompilation -> C:\work\StackExchange.Precompilation\StackExchange.Precompilation\bin\Debug\net472\StackExchange.Precompilation.dll
  StackExchange.Precompilation.Build -> C:\work\StackExchange.Precompilation\StackExchange.Precompilation.Build\bin\Debug\net472\StackExchange.Precompiler.exe
  Test.Module -> C:\work\StackExchange.Precompilation\Test.Module\bin\Debug\net472\Test.Module.dll
  StackExchange.Precompilation.MVC5 -> C:\work\StackExchange.Precompilation\StackExhcange.Precompilation.MVC5\bin\Debug\net472\StackExchange.Precompilation.MVC5.dll
  Test.ConsoleApp -> C:\work\StackExchange.Precompilation\Test.ConsoleApp\bin\Debug\net472\Test.ConsoleApp.exe
  Test.WebApp.ExternalViews -> C:\work\StackExchange.Precompilation\Test.WebApp.ExternalViews\bin\Debug\net472\Test.WebApp.ExternalViews.dll
C:\work\StackExchange.Precompilation\Test.WebApp\MvcApplication.cs(29,13): error CS0012: The type 'Action<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes'. [C:\work\StackExchange.Precompilation\Test.WebApp\Test.WebApp.csproj]
  StackExchange.Precompilation.Tests -> C:\work\StackExchange.Precompilation\StackExchange.Precompilation.Tests\bin\Debug\net472\StackExchange.Precompilation.Tests.dll
MSBuild failed

The change is:

  1. Add NuGet reference to Common.Logging
  2. Call ILog.Info

https://github.com/MarkKharitonov/StackExchange.Precompilation/commit/13a2c5f4a27915307d0a403d1c73f0922da87ebe

And now it fails with the error message

C:\work\StackExchange.Precompilation\Test.WebApp\MvcApplication.cs(29,13): error CS0012: The type 'Action<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes'. [C:\work\StackExchange.Precompilation\Test.WebApp\Test.WebApp.csproj]

Now I understand that StackExchange.Precompilation copies the logic of csc.exe code from 7 years ago. Unfortunately, so far it is the best I have to replace aspnet_compiler.exe.

So my question is simple - how do we fix it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文