9

My solution contains some .net projects and one of them is a ASP.NET MVC project, which I'm trying to publish. All configurations are set correctly, x32 and x64, non of them is set to AnyCPU.

Problem:

If I try to publish the project as 32bit, everything is fine, but trying to publish in 64 bit mode fails with an error:

Could not load file or assembly "ProjectA" or one of its dependencies. 
An attempt was made to load a program with an incorrect format.

What I've tried and noticed:

Since VS 2013, MSbuild is a part of VS and not of .NET Framework as before. If I simply build the solution in x64 mode, the 32 bit msbuild "C:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe" is runnig first and it launches the 64bit msbuild "C:\Program Files (x86)\MSBuild\12.0\Bin\amd64\MSBuild.exe" So normal build without publish works just fine.

But, if I choose publish, the 32bit MSbuild is running first and then it launches the 32 bit aspnet_compiler c:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_compiler.exe and NOT the 64 bit one, which causes an error which I mentioned above.

The only workaround I've found until now is to replace the

"C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe"

with a 64 bit one

"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_compiler.exe"

Question:

Is there any better (legal) solution for my problem? This looks like a bug in VS

VladL
  • 12,769
  • 10
  • 63
  • 83
  • File the bug on connect: https://connect.microsoft.com/VisualStudio – jessehouwing Nov 13 '13 at 16:17
  • @jessehouwing thanks for your idea https://connect.microsoft.com/VisualStudio/feedback/details/808519/visual-studio-2013-calls-32-bit-aspnet-compiler-instead-of-64-bit-one – VladL Nov 14 '13 at 09:29
  • 1
    This is a joke, right? The whole transition from VS 2010 -> 2012 -> 2013 gives me such headaches and i am still struggling to get all my asp.net webforms and mvc project to build, run and deploy correctly. On top of that the desastrous Sql Data Tool support for vs 2013. Where is MS going? – ovm Mar 13 '14 at 13:27
  • 2
    @ovm yes, I love such jokes very much :). Feel free to upvote it here and especially here https://connect.microsoft.com/VisualStudio/feedback/details/808519/visual-studio-2013-calls-32-bit-aspnet-compiler-instead-of-64-bit-one – VladL Mar 13 '14 at 13:32

3 Answers3

8

Add this line to the .csproj file within a PropertyGroup node for the build configuration you are targeting (or use the ProperyGroup that doesn't have a target to target all release modes).

<AspnetCompilerPath>$(windir)\Microsoft.NET\Framework64\v4.0.30319</AspnetCompilerPath>

The 64-bit version is then used by the compiler. For me, the node I added this line to was as below:

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
   <AspnetCompilerPath>$(windir)\Microsoft.NET\Framework64\v4.0.30319</AspnetCompilerPath>
</PropertyGroup>
simbolo
  • 7,279
  • 6
  • 56
  • 96
  • Thanks, we had to write our own build batches, will try it later with the new project, unless microsost has fixed it. – VladL Jul 31 '14 at 09:14
1

I have exactly the same problem.

You can create BAT-files to replace the EXE before you start your publish. or Or you could write a BAT that calls the aspnet_compiler.exe directly and does the publish without the UI :-)

ahorak
  • 123
  • 8
1

Add this line to the .pubxml file (Tree Solution\Project\Properties\PublishProfiles\.pubxml) within a PropertyGroup node for the publish configuration. For example:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <AspnetCompilerPath>$(windir)\Microsoft.NET\Framework64\v4.0.30319</AspnetCompilerPath>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <publishUrl>C:\Pub\FTS_Service</publishUrl>
    <DeleteExistingFiles>True</DeleteExistingFiles>
    <PrecompileBeforePublish>True</PrecompileBeforePublish>
    <EnableUpdateable>True</EnableUpdateable>
    <DebugSymbols>False</DebugSymbols>
    <WDPMergeOption>DonotMerge</WDPMergeOption>
  </PropertyGroup>
</Project>