我正在尝试在Visual Studio 2012中设置我的老板刚刚给我安装的web应用程序项目。
当我通过.sln
文件在VS中打开项目时,它会出现以下错误:
The imported project "..\.nuget\nuget.targets" was not found. Confirm that path in the ,<Import> declaration is correct and that the file exist on disk.
所以我在SO上找到了解决方案并删除了以下行格式.csproj
文件:
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
并且这次正确打开时重新加载项目但是当我构建项目时它给出了以下错误:
Assembly 'System.Web.Http.Cors, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' uses 'System.Web.Http, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
这是packages.config
文件:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AutoMapper" version="3.1.0" targetFramework="net45" />
<package id="EntityFramework" version="6.0.0-beta1" targetFramework="net45" />
<package id="Microsoft.AspNet.Cors" version="5.0.0-beta2" targetFramework="net45" />
<package id="Microsoft.AspNet.Mvc" version="4.0.30506.0" targetFramework="net45" />
<package id="Microsoft.AspNet.Mvc.FixedDisplayModes" version="1.0.1" targetFramework="net45" />
<package id="Microsoft.AspNet.Razor" version="2.0.30506.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi" version="4.0.30506.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.0.0-beta2" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.0.0-beta2" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Cors" version="5.0.0-beta2" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="4.0.30506.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebPages" version="2.0.30506.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebPages.Data" version="2.0.20710.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebPages.WebData" version="2.0.30506.0" targetFramework="net45" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
<package id="Mvc4Futures" version="4.0.20710.0" targetFramework="net45" />
<package id="Newtonsoft.Json" version="5.0.6" targetFramework="net45" />
</packages>
然后我从包管理器控制台安装了Microsoft.AspNet.WebApi 4.0.30506.0
和Microsoft.AspNet.WebApi.Cors 5.0.0-beta2
。
现在项目已成功构建,但是当我执行项目时,我收到以下错误:
Attempt by security transparent method 'System.Web.Http.Cors.EnableCorsAttribute..ctor(System.String, System.String, System.String, System.String)' to access security critical method 'System.Web.Cors.CorsPolicy..ctor()' failed.
Assembly 'System.Web.Http.Cors, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is marked with the AllowPartiallyTrustedCallersAttribute, and uses the level 2 security transparency model. Level 2 transparency causes all methods in AllowPartiallyTrustedCallers assemblies to become security transparent by default, which may be the cause of this exception.
在这一行:
var cors = new EnableCorsAttribute("*", "*", "*");
请指导我。
感谢名单。
答案 0 :(得分:1)
.net framework 4.0以后,程序集默认为安全关键。解决方案是删除程序集中定义它的AllowPartiallyTrustedCallersAttribute属性,或将其添加到所有程序集。
尝试添加:
[assembly: AllowPartiallyTrustedCallers()] to your assemblyinfo.cs
不要忘记添加: 在开始时使用assemblyinfo.cs文件中的System.Security
答案 1 :(得分:0)
打开Visual Studio 2012.转到文件 - &gt;新建项目 - &gt;选择ASP.NET MVC 4 Web应用程序,给出一个名称,为解决方案文件添加位置路径,为解决方案命名,然后按OK。希望这样可行。 如果它不起作用,请更新您的nuget包。右键单击解决方案,然后单击Manage Nuget Packages for Solution并安装解决方案所需的包。
答案 2 :(得分:0)
确定,
Thanx everyone。
我通过以下方式解决了这个问题:
感谢名单。