CLR DLL在VS中部署良好,但不通过MSBuild

时间:2015-05-01 15:02:41

标签: c# .net sql-server visual-studio msbuild

我正在尝试将一些构建脚本与.NET项目放在一起,并将一些CLR代码部署到SQL Server。如果我通过选择“Build”在Visual Studio中构建DLL,我已经签署了程序集并可以将其部署为存储过程。在EXTERNAL ACCESS的登录下部署后,运行存储过程可以正常工作。

但是,如果我使用MSBuild脚本编译DLL,则在部署(相同进程)并尝试运行存储过程后,我在SQL Server中收到以下错误:

Msg 10314, Level 16, State 11, Line 5
An error occurred in the Microsoft .NET Framework while trying to load assembly id 65562. The server may be running out of resources, or the assembly may not be trusted with PERMISSION_SET = EXTERNAL_ACCESS or UNSAFE. Run the query again, or check documentation to see how to solve the assembly trust issues. For more information about this error: 
System.IO.FileLoadException: Could not load file or assembly 'assembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ea3705e3b2b05e85' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
System.IO.FileLoadException: at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) at System.Reflection.Assembly.Load(String assemblyString)

我的MSBuild文件只是在我的解决方案中调用项目文件的构建:

<MSBuild Projects="Project1/Project1.csproj" Targets="Build" />

我怀疑它可能是一个目标框架问题(我需要将它作为.NET 2.0,并且已针对此进行配置),但使用/p:TargetFrameworkVersion=v2.0仍然无效。

为什么这两个编辑有所不同?

编辑:我正在尝试为任何CPU编译

1 个答案:

答案 0 :(得分:1)

想出来:

菜鸟错误。出于某种原因,MSBuild不使用默认目标组装平台。这个msbuild调用可以强制平台汇编:

msbuild script.msbuild /p:Platform="AnyCPU" /p:Configuration=Release

感谢这个链接小费(虽然“任何CPU”有空格不起作用):

https://candritzky.wordpress.com/2011/02/03/msbuild-for-64-bit-any-cpu-platform/