我的解决方案包含一些.net项目,其中一个是ASP.NET MVC项目,我正在尝试发布。所有配置都设置正确,x32和x64,其中没有设置为AnyCPU。
问题:
如果我尝试将项目发布为32位,一切都很好,但尝试以64位模式发布失败并显示错误:
Could not load file or assembly "ProjectA" or one of its dependencies.
An attempt was made to load a program with an incorrect format.
我尝试过并注意到了:
自VS 2013以来,MSbuild是VS的一部分,而不是以前的.NET Framework。如果我只是在x64模式下构建解决方案,则首先运行32位msbuild "C:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe"
并启动64位msbuild "C:\Program Files (x86)\MSBuild\12.0\Bin\amd64\MSBuild.exe"
所以正常构建没有发布工作正常。
但是,如果我选择publish
,则首先运行32位MSbuild,然后启动32位aspnet_compiler c:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_compiler.exe
而不是64位,这会导致上面提到的错误。
我到目前为止找到的唯一解决方法是更换
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe"
64位一个
"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_compiler.exe"
问题:
我的问题有更好的(合法的)解决方案吗?这看起来像VS
中的错误答案 0 :(得分:8)
将此行添加到PropertyGroup
节点内的.csproj文件中,以获取您要定位的构建配置(或使用没有目标的ProperyGroup
来定位所有版本模式)
<AspnetCompilerPath>$(windir)\Microsoft.NET\Framework64\v4.0.30319</AspnetCompilerPath>
然后编译器使用64位版本。对我来说,我添加此行的节点如下:
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<AspnetCompilerPath>$(windir)\Microsoft.NET\Framework64\v4.0.30319</AspnetCompilerPath>
</PropertyGroup>
答案 1 :(得分:1)
我有完全相同的问题。
您可以在开始发布之前创建BAT文件以替换EXE。 要么 或者你可以编写一个直接调用aspnet_compiler.exe的BAT,并在没有UI的情况下进行发布 : - )
答案 2 :(得分:1)
将此行添加到PropertyGroup节点中的.pubxml文件(Tree Solution \ Project \ Properties \ PublishProfiles \ .pubxml)以进行发布配置。
例如:
<?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>
<?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>