2

I dont really know much about this to be honest with you...

I have managed to download mscommunity build and I have managed to use the script below to successfully compile and build my application, however I want to get my asp.net mvc application "published" so I want the same files that you when clicking "publish" inside visual studio. My current build file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
     <!-- Import the MSBuild Tasks -->
  <Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>
    <ClassLibraryOutputDirectory>c:\publish\</ClassLibraryOutputDirectory>
    <ProjectDir>..\PetProject\</ProjectDir >
    <ProjectTestDir>$(ProjectDir)PetProject.WebUI\</ProjectTestDir >
    <ProjectFile>$(ProjectDir)PetProject.sln</ProjectFile >
    <TestProjectFile>$(ProjectTestDir)PetProject.WebUI.csproj</TestProjectFile >
  </PropertyGroup>

  <!-- Build projects by calling the Project files generated by VS -->
  <Target Name="Build">
    <MSBuild Projects="$(ProjectFile)" />
    <MSBuild Projects="$(TestProjectFile)" />
  </Target>

</Project>

I call this in command line using:

C:\Windows\Microsoft.NET\Framework\v3.5>msbuild.exe C:\Projects\PetProject\build
\PetProject.build

Help is greatly appreciated...

NOTE: I want to avoid CI, Nant etc. because I dont really know what they are and I ideally want to get the above working as First Base, then move onto other things like CI or whatever else, I dont want to confuse myself too much...

1 Answer 1

4

This should give you the same result as publishing from within Visual Studio:

<Project DefaultTargets="BuildAndPublish" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets" />

    <PropertyGroup>
        <ProjectFile>C:\PetProject\PetProject.csproj</ProjectFile >
        <OutDir>C:\PetProject\MyPublish</OutDir>
    </PropertyGroup>

    <Target Name="BuildAndPublish">
        <MSBuild Projects="$(ProjectFile)" Targets="Package" Properties="Configuration=Release;PackageLocation=$(OutDir)\MSDeploy\Package.zip;_PackageTempDir=$(OutDir)\Temp" />
    </Target>

</Project>

for your project.

Don't forget to import Microsoft.Web.Publishing.targets which contains the Package target (which I mixed up with Publish in my inital answer).

If you want to build your solution your script should look something like this:

<Project DefaultTargets="BuildAndPublish" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets" />

    <PropertyGroup>
        <OutDir>C:\PetProject\MyPublish\</OutDir>
    </PropertyGroup>

    <ItemGroup>
        <Solution Include="C:\PetProject\PetProject.sln">
            <Properties>
                OutDir=$(OutDir);
                Platform=Any CPU;
                Configuration=Release;
                DeployOnBuild=True;
                DeployTarget=Package;
                PackageLocation=$(OutDir)\MSDeploy\Package.zip;
                _PackageTempDir=$(OutDir)\Temp
            </Properties>
        </Solution>
    </ItemGroup>

    <Target Name="BuildAndPublish">
        <MSBuild Projects="@(Solution)" />
    </Target>

</Project>

There's a blog post by Code Inside which describes basically the same approach but didn't work when I tried it in my environment.

Sign up to request clarification or add additional context in comments.

5 Comments

How would I target the publish to output to my output directory? I could not get that bit...
Sorry that my inital answer didn't work - I mixed up Publish (which only works for ClickOnce deployable projects and Package.
Its cool... I assume this requires visual studio to be on the server? (My server does not have visual studio installed! :( )
Sorry my application is Asp.net MVC2 targeting asp.net 3.5 not 4.0
@Haroon I'll see if I can set up an example with your specs - it should be possible without VS on your build machine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.