问题
This is a similar question to How do I deploy a web application using F# to Azure Web Site. My C#/F# MVC project uses the FSharp.Data NuGet package, and the deployment process fails with the message
Could not locate the assembly "FSharp.Data, Version=1.1.4.0, Culture=neutral, PublicKeyToken=null".
The only effective workaround I can see is to replace all of the NuGet references (FSharp.Data, FSharp.Data.DesignTime, FSharp.Data.Experimental, FSharp.Data.Experimental.DesignTime) with explicit references to the DLLs, and Copy Local set to true. I am loath to throw the NuGet baby out with the bathwater in this way. Is there a cleverer way? Alternatively, is there an open issue to which I can add my vote?
回答1:
You can add a <dependentAssembly> element to your web.config
to make sure the FSharp.Data
assembly is included when your project is deployed to Azure. I've used this technique before when deploying mixed F#/C# ASP.NET MVC projects to Azure; it's been a while, but I don't think I had to change the Copy Local
setting on the referenced assemblies (which I added via NuGet).
Anyway, the entry you need to add should look something like this:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="FSharp.Data" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Based on Rob's comment that he's still getting the same error message, here're the next steps I would take to diagnose the issue.
- Build the Azure deployment package (you don't need to deploy it). When it's finished building, find the deployment package file (
*.cspkg
); this is actually just a zip file, so extract the contents into a folder, e.g., with 7-zip. In the extracted folder, there should be one file with the*.cssx
extension which is much larger than the others; it's also a zip file, so extract it into another folder, then browse into that folder with Windows Explorer. From there, go into thesitesroot
folder, then the0
folder. You should now be looking at the root of your website (i.e., the files/folders that'll be copied toC:\inetpub\wwwroot
on the web server). Check thebin
folder -- do you see theFSharp.Data
assembly there? If not, this is a build/packaging problem, not a server problem; if you do see theFSharp.Data
assembly, proceed to the next step. - Deploy your project to Azure, then Remote Desktop into one of the instances your project is being hosted on. (There's a special procedure for enabling Remote Desktop on the instances -- if you haven't done this yet, you'll need to do so before continuing.) Once you're logged in, you can open Event Viewer (under Administrative Tools); look at the Application log under Windows Logs -- are there any ASP.NET errors there? If so, click them and look at the error message, it may contain a .NET exception message about not being able to resolve the
FSharp.Data
assembly. If it does, browse toC:\inetpub\wwwroot\
and make sureFSharp.Data
is in thebin
folder of the website. If it is, proceed to the next step. If the
FSharp.Data
assembly is being packaged and deployed correctly along with your web project, then there could be some issue arising with it (or one of it's dependencies) being a .NET 4.0 assembly when your project is running on .NET 4.5. While logged in to the Azure instance (via Remote Desktop) you could enable Fusion logging and use the Fusion log viewer to trace how the CLR is attempting to load the assembly. If you do track down the issue, the likely way to fix it will be to add a<bindingRedirect>
element within the<dependentAssembly>
entry you created in yourweb.config
. Here's how I did it to get the original F# PowerPack (which targeted the .NET 2.0 version ofFSharp.Core
) working in my F#/C# project on .NET 4.0:<dependentAssembly> <assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" /> </dependentAssembly>
来源:https://stackoverflow.com/questions/17221978/deployment-of-a-web-application-using-fsharp-data-to-azure-websites