Publish ClickOnce Application using Microsoft.Build Namespaces

356 Views Asked by At

I have a project that is saved to a file location that I want to be able to publish. The project has all the publish properties set and I would like these properties to be used (URLs etc..)

I currently have the following code that creates a Build:

        string projectFileName = @"C:\ePortfolio_Client\ePortfolio_Client.vbproj";

        var pc = new ProjectCollection();
        pc.SetGlobalProperty("Configuration", "Release");
        pc.SetGlobalProperty("Platform", "Any CPU");
        BuildManager.DefaultBuildManager.Build(new BuildParameters(pc), new BuildRequestData(new ProjectInstance(projectFileName), new string[] { "Rebuild" }));

but I really need to take this the next step further and publish it.

I have come across the namespace Microsoft.Build.Tasks.Deployment.ManifestUtilities however I do not have a clue on how I might use this for what I need?


Edit


I have had some advice but still just falling short. I have the following setup now:

I have a project exported to a file location and I am writing an application that will publish this.

In the project I am looking to publish I have made the following changes:

vbproj file: I have added the following

  <PropertyGroup>
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
  </PropertyGroup>


  <Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
  <Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v14.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />

In a seperate Web Project, I have created a pubxml file and copied this into the project I am looking to publish. This contains the following:

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <publishUrl>\\ **Location to publish the Project ** \</publishUrl>
    <DeleteExistingFiles>False</DeleteExistingFiles>
  </PropertyGroup>
</Project>

The vbproj file mentioned above already contains the publish settings I wish to use so one question I have is - do I need to copy them into this pubxml file?

From with the application a am writing (to publish the project) - I am initiating a build using the following:

        string projectFileName = Properties.Settings.Default.SolutionLocation + @"\ePortfolio_Client\ePortfolio_Client.vbproj";

        var pc = new ProjectCollection();
        pc.SetGlobalProperty("Configuration", "Release");
        pc.SetGlobalProperty("Platform", "Any CPU");
        pc.SetGlobalProperty("PublishProfile", "ePublish");
        pc.SetGlobalProperty("DeployOnBuild", "True");
        pc.SetGlobalProperty("DeployTarget", "MSDeployPublish");

        BuildManager.DefaultBuildManager.Build(new BuildParameters(pc), new BuildRequestData(new ProjectInstance(projectFileName), new string[] { "Rebuild" }));

Which seems to build the project, but i'm still not getting a publication. I hope this extra detail gives someone a little more to work on in helping me get this working!

0

There are 0 best solutions below