错误CS0012:类型...在未引用的程序集中定义。您必须添加对程序集 'mscorlib, Version=2.0.5.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
更改是:
- 将 NuGet 引用添加到 Common.Logging
- 调用
ILog.Info
现在它失败并显示错误消息
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:
- Add NuGet reference to Common.Logging
- Call
ILog.Info
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论