VS2022当安装在非默认路径时,每次更新后,在发布时,就会出来编译失败的提示,比如这样:
C:\VS2022\Preview\MSBuild\Microsoft\VisualStudio\v17.0\Web\Transform\Microsoft.Web.Publishing.AspNetCompileMerge.targets(132,5): 错误 : Can't find the valid AspnetMergePath
这时关闭VS,用管理员模式(不然改了不能保存)打开一个记事本,然后打开上面的这个文件,查找AspnetMergePath是这样的
<Target
Name="GetAspNetMergePath" DependsOnTargets="$(GetAspNetMergePathDependsOn)" Condition ="'$(GetAspNetMergePath)' != 'false'"> <PropertyGroup> <AspnetMergeName>aspnet_merge.exe</AspnetMergeName> <AspnetMergePath Condition="Exists('$(TargetFrameworkSDKToolsDirectory)$(AspnetMergeName)')">$(TargetFrameworkSDKToolsDirectory)</AspnetMergePath> </PropertyGroup> <Error Condition="'$(AspnetMergePath)' == '' Or !Exists($(AspnetMergePath))" Text="Can't find the valid AspnetMergePath" /> </Target>
在AspnetMergePath 这一节,可以看到它需要一个TargetFrameworkSDKToolsDirectory,因为AspnetMergeName,即aspnet_merge.exe就放这里面。但恰恰就是这个变量不存在。
去C盘找这个文件,原来放在C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools里面。
把这个路径添加进去,跟在AspnetMergeName后面就行,注意路径最后要加一个反斜杠,因为在引用的时候后面直接带了文件名,如果不加反斜杠,还是会说找不到文件。
<PropertyGroup>
…… <AspnetMergeName>aspnet_merge.exe</AspnetMergeName> <TargetFrameworkSDKToolsDirectory>C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\</TargetFrameworkSDKToolsDirectory> …… </PropertyGroup>
再打开VS发布编译就没问题了。
标签:WEB,编译,merge,VS,2022,AspnetMergePath,Microsoft,aspnet From: https://www.cnblogs.com/glowinghe/p/17511074.html