0

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!

CJH
  • 1,266
  • 2
  • 27
  • 61
  • there is a property `DeployOnBuild=true` https://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.build.workflow.activities.msbuild.deployonbuild.aspx – Sebastian Siemens May 06 '16 at 09:54
  • Ahh, that sounds about what im looking for! Thanks Sebastian! I have just tried adding that in as: pc.SetGlobalProprty(DeployOnBuild", "True"); however the project does still not appear to be publishing to the expected location? Do you know if I would need to use DeployOnBuild in a different way? – CJH May 06 '16 at 10:00
  • Please have a look at http://stackoverflow.com/questions/18618467/tfs-msbuild-args-pdeployonbuild-true-doesnt-seem-to-do-anything. There are some prerequisites for it to work with MSBuild. And have a look here: http://codegur.com/24457091/how-do-i-build-a-mvc-4-solution-programatically-in-4-5-framework – Sebastian Siemens May 06 '16 at 10:13
  • Thanks for those as well... I have looked specifically at the first one (as the second link seems to be more a question without answers??) and still not having any luck publishing from build...?? Im guessing the build doesn't need to be initiated from the actual build server?? – CJH May 06 '16 at 13:04
  • the second link was just an example of the syntax. Do you have a publish profile (`myProfile.pubxml`)? Please create this publish profile and add this to properties (`pc.SetGlobalProperty("PublishProfile", [Name of My Profile (without a file extension)]);`). – Sebastian Siemens May 06 '16 at 13:17
  • Ahh I will try and give that a go today... Do you recommend creating a publish file from an external Web App on a separate project? – CJH May 08 '16 at 07:55
  • I have created a .PUBXML file in the project I am trying to publish. I created originally on a seperate Web Project and copied it over to the project I am looking to publish by this app I am writing. There are obviously some properties in there so I guess I need to change some of them?? My current publish settings are in the projects vbproj file so are they able to just be copied over into the ProprtyGroup of the new pubXML file? (I have also made the references to the targets in the project file I want to publish). – CJH May 09 '16 at 08:51
  • ... I may make an Edit to the original question with the details I currently have following your help! – CJH May 09 '16 at 08:51

0 Answers0