Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AspNetCompiler uses the wrong target framework #87

Open
OronDF343 opened this issue Dec 9, 2024 · 4 comments
Open

AspNetCompiler uses the wrong target framework #87

OronDF343 opened this issue Dec 9, 2024 · 4 comments
Labels
question Further information is requested

Comments

@OronDF343
Copy link

When attempting to precompile an ASP.NET WebForms app, the wrong version of aspnet_compiler.exe is chosen, and the wrong target framework version is used.

Example pubxml:

<?xml version="1.0" encoding="utf-8"?>
<Project>
	<PropertyGroup>
		<WebPublishMethod>Package</WebPublishMethod>
		<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
		<LastUsedPlatform>Any CPU</LastUsedPlatform>
		<SiteUrlToLaunchAfterPublish />
		<LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
		<ExcludeApp_Data>false</ExcludeApp_Data>
		<DesktopBuildPackageLocation>$(ProjectDir)\..\publish\package.zip</DesktopBuildPackageLocation>
		<PackageAsSingleFile>true</PackageAsSingleFile>
		<_TargetId>IISWebDeployPackage</_TargetId>
		<PrecompileBeforePublish>True</PrecompileBeforePublish>
		<EnableUpdateable>False</EnableUpdateable>
		<DebugSymbols>True</DebugSymbols>
		<WDPMergeOption>DonotMerge</WDPMergeOption>
	</PropertyGroup>
</Project>

This example results in the 32-bit version of aspnet_compiler.exe being used. Adding <Platform>x64</Platform> makes it use the 64-bit one, but it still targets an older framework version (maybe 4.0 as in #70 ?), which causes errors such as error CS0117: 'System.Net.SecurityProtocolType' does not contain a definition for 'Tls12'.

@CZEMacLeod CZEMacLeod added the question Further information is requested label Dec 10, 2024
@CZEMacLeod
Copy link
Owner

Can you confirm what command you are using to publish your project, and which version of Visual Studio you have installed.
Might also help to know which versions of the framework SDK and targeting packs you have too (from the VS installer components).

If you can push a minimal example project to github I might be able to replicate and help.

@OronDF343
Copy link
Author

I've created a test repo: https://github.com/OronDF343/WebFormsSdkTest

Two commands are included, publish.bat and publish64.bat which forces 64-bit for the profile. The commands also output a web package to C:\test.

@CZEMacLeod
Copy link
Owner

CZEMacLeod commented Dec 11, 2024

Thanks - I replicated the issue with publish - I'll have to look further into that but it looks like replacing TargetPlatform with Platform in the main project is fine. This might be something to do with dotnet/sdk#1553 but I'm not sure yet.
I don't get any issues with compilation or target frameworks (e.g. CS0117).
image
I am on windows 11 so have net framework 4.8.1 installed.

C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319\aspnet_compiler.exe
Microsoft (R) ASP.NET Compilation Tool version 4.8.9032.0
Utility to precompile an ASP.NET application
Copyright (C) Microsoft Corporation. All rights reserved.

@OronDF343
Copy link
Author

Thanks, I have been able to confirm that the issue with .NET version is not reproducible in the test project. It appears to be related to the particular publish profile having excluded web.config and included it from a test file in a different directory:

    ...
    <ExcludeFilesFromDeployment>web.config</ExcludeFilesFromDeployment>
    <ExcludeFoldersFromDeployment>WebConfigs</ExcludeFoldersFromDeployment>
</PropertyGroup>
<Target Name="AdditionalFilesForPackage" AfterTargets="CopyAllFilesToSingleFolderForPackage;CopyAllFilesToSingleFolderForMsdeploy">
    <Copy SourceFiles="$(ProjectDir)\WebConfigs\web.production.txt" DestinationFiles="$(_PackageTempDir)\web.config" OverwriteReadOnlyFiles="true" />
</Target>

For now, I was able to work around it with this target:

<Target Name="ReplaceConfig" AfterTargets="CopyAllFilesToSingleFolderForAspNetCompileMerge">
    <Copy SourceFiles="$(ProjectDir)\WebConfigs\web.production.txt" DestinationFiles="$(CopyBeforeAspnetCompileMergeTargetPath)\web.config" OverwriteReadOnlyFiles="true" />
</Target>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants