0

I have a solution with many projects, some of which have an Outputtype of exe.

I'm using the following arguments as part of my MsBuild call

/target:publish /p:PublishDir="$(build.artifactstagingdirectory)\

However, this publishes all projects with an Outputtype of exe. However, I only want to publish one specific project.

Most of what I have read states to reference the named PublishProfile. However, I don't see a way of creating a PublishProfile for this project type. When I click Publish I get a basic publish wizard and the publish settings are stored in the .csproj file not a .pubxml file. So how can I request a specific project to be published?

MatSnow
  • 7,357
  • 3
  • 19
  • 31
PatrickNolan
  • 1,671
  • 2
  • 20
  • 40
  • Do you want to build the solution but only publish a specific project with one MSBuild command line? How about publish the specific project with a command line: `msbuild "xx.csproj" /target:publish /p:PublishDir="$(build.artifactstagingdirectory)\"`? – Leo Liu Nov 08 '17 at 10:28

1 Answers1

0

However, I don't see a way of creating a PublishProfile for this project type. When I click Publish I get a basic publish wizard and the publish settings are stored in the .csproj file not a .pubxml file. So how can I request a specific project to be published?

The PublishProfile is used for web project not click once. Just as you said, "basic publish wizard and the publish settings are stored in the .csproj file not a .pubxml file", so PublishProfile should not be a correct option.

If you want to publish a specific project from solution with msbuild, the simple way is to build the entire solution but only publish one project file, like:

msbuild.exe "ProjectName.csproj" /target:publish /p:PublishDir="$(build.artifactstagingdirectory)\

If using one command line to build and publish is your persistence, you can custom a target to publish the project in the project file, which you want to publish. For example:

<PropertyGroup>
    <!-- the folder of the project to build -->
    <ProjLocation>..\YourProjectFolder</ProjLocation>
    <ProjLocationReleaseDir>$(ProjLocation)\bin\Release</ProjLocationReleaseDir>
    <ProjPublishLocation>$(ProjLocationReleaseDir)\app.publish</ProjPublishLocation>
    <!-- This is the web-folder, which provides the artefacts for click-once. After this
     build the project is actually deployed on the server -->
    <DeploymentFolder>D:\server\releases\</DeploymentFolder>
</PropertyGroup>


<Target Name="Publish" DependsOnTargets="Clean">
    <Message Text="Publish-Build started for build no $(ApplicationRevision)" />
    <MSBuild Projects="$(ProjLocation)/YourProject.csproj" Properties="Configuration=Release" Targets="Publish"/>   


    <ItemGroup>
        <SchoolPlannerSetupFiles Include="$(ProjPublishLocation)\*.*"/>
        <SchoolPlannerUpdateFiles Include="$(ProjPublishLocation)\Application Files\**\*.*"/>
    </ItemGroup>
    <Copy
        SourceFiles="@(SchoolPlannerSetupFiles)"
        DestinationFolder="$(DeploymentFolder)\"
    />
    <Copy
        SourceFiles="@(SchoolPlannerUpdateFiles)"
        DestinationFolder="$(DeploymentFolder)\Application Files\%(RecursiveDir)"
    />      
    <CallTarget Targets="RestoreLog"/>
</Target>
<Target Name="Clean">   
    <Message Text="Clean project:" />
    <MSBuild Projects="$(ProjLocation)/YourProject.csproj" Properties="Configuration=Release" Targets="Clean"/>
</Target>       

With this custom target, you do not need to publish the project, just need build the solution.

Hope this helps.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135