Publishing my asp.net mvc application via script a

2020-07-27 04:29发布

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条回答
冷血范
2楼-- · 2020-07-27 04:56

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.

查看更多
登录 后发表回答