I have an ASP.NET webforms project (A) which references two other webforms projects (B and C) that I'm trying to publish with precompilation enabled from the command line with MSBuild using a publish profile (.pubxml
). I need to be able to script this for our build pipeline to create the appropriate artifact for a security scan.
I can publish project A from Visual Studio just fine; it precompiles and outputs in bin/app.publish
as expected.
When I run the following MSBuild command it creates the app.publish directory with a _PublishedWebsites
directory containing projects A, B, and C without precompilation.
msbuild .\path\to\projectA.csproj /p:DeployOnBuild=true /p:PublishProfile=MyPublishProfile /p:OutputPath=$(pwd)\app.publish
MyPublishProfile.pubxml
:
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<DeleteExistingFiles>true</DeleteExistingFiles>
<ExcludeApp_Data>true</ExcludeApp_Data>
<LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
<LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<PublishProvider>FileSystem</PublishProvider>
<PublishUrl>bin\app.publish\</PublishUrl>
<WebPublishMethod>FileSystem</WebPublishMethod>
<_TargetId>Folder</_TargetId>
<SiteUrlToLaunchAfterPublish />
<PrecompileBeforePublish>true</PrecompileBeforePublish>
<EnableUpdateable>false</EnableUpdateable>
<DebugSymbols>true</DebugSymbols>
<WDPMergeOption>CreateSeparateAssembly</WDPMergeOption>
<UseFixedNames>true</UseFixedNames>
</PropertyGroup>
</Project>
The only difference for projects B and C is that PrecompileBeforePublish
is set to false
in the .pubxml
because I get assembly binding errors when it tries to precompile them.
Is there a way to direct MSBuild that I only want project A published, the way Visual Studio does?
-
Not clear what benefits are by having multiple web site projects in one project. You still in theory required to deploy/publish each project as separate anyway, so I don't know what you gain here. If you looking to share code, then move that code out to a separate class of which then any and all of the 3 projects can reference that "code only" class project - and that will work correctly. Regardless, you would have to configure each subfolder as a whole new "separate" site anyway - once again, I see little benefits here. Sharing some common code in a new project class is easy, and works well.Albert D. Kallal– Albert D. Kallal2025年10月02日 04:01:28 +00:00Commented Oct 2 at 4:01