Pregunta

I'm using a msbuild file, TeamCity and Web Deploy to deploy my siteand everything works just fine, for the files included in the Visual Studio csproj file. In addition to these files I want to publish a couple of more files such as license files etc depending on environment.

This is my build file DeployToTest.proj:

<Project DefaultTargets="Deploy" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<ItemGroup>
<LicenseSourceFiles Include="License.config"/>
<RobotSourceFile Include="robots.txt" />
</ItemGroup>

<Target Name="Build">
<Message Text="Starting build" />
<MSBuild Projects="..\..\WebApp.sln" Properties="Configuration=Test" ContinueOnError="false" />
<Message Text="##teamcity[buildNumber '$(FullVersion)']"/>
<Message Text="Build successful" />
</Target>

<Target Name="Deploy" DependsOnTargets="Build">
<Copy SourceFiles="@(LicenseSourceFiles)" DestinationFolder="..\..\wwroot"></Copy>
<Copy SourceFiles="@(RobotSourceFile)" DestinationFolder="..\..\wwwroot"></Copy>

<Message Text="Started deploying to test" />
<Exec Command="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe ..\..\wwwroot\WebApp.csproj /property:Configuration=Test /t:MsDeployPublish /p:MsDeployServiceUrl=99.99.99.99;DeployIisAppPath=MySite;username=user;password=pass;allowuntrustedcertificate=true" />
<Message Text="Finished deploying to test" />
</Target>
</Project>

As you can see I tried to copy the license.config and robots.txt without any luck.

This .proj file is selected as the 'Build file path' in TeamCity.

Any suggestions on how I can accomplish this?

¿Fue útil?

Solución 2

Solution was to change settings for the web project in Visual Studio. Under Package/Publish Web i set 'Items to deploy' to 'All files in this project folder'. I then added a filter to remove all .cs files and other unwanted files.

Otros consejos

To solve this problem it may be worth executing the build script with the verbosity set to the 'detailed' or 'diagnostic' level. That should tell you exactly why the copy step fails.

However one of the most likely problems could be the fact that the script is using relative file paths, which depend on the working directory being set to the correct value. For build scripts I prefer use absolute paths to prevent any file path problems.

To get the absolute path you can use the MSBuildProjectDirectory property. The value of this property points to the path of the directory containing the currently executing MsBuild script. With that you can change your MsBuild script like this:

<Project DefaultTargets="Deploy" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
    <PropertyGroup>
        <BaseDir>$(MSBuildProjectDirectory)</BaseDir>
    </PropertyGroup>

    <ItemGroup>
        <LicenseSourceFiles Include="$(BaseDir)\License.config"/>
        <RobotSourceFile Include="$(BaseDir)\robots.txt" />
    </ItemGroup>

    <Target Name="Build">
        <Message Text="Starting build" />
        <MSBuild Projects="$(BaseDir)\..\..\WebApp.sln" Properties="Configuration=Test" ContinueOnError="false" />
        <Message Text="##teamcity[buildNumber '$(FullVersion)']"/>
        <Message Text="Build successful" />
    </Target>

    <Target Name="Deploy" DependsOnTargets="Build">
        <Copy SourceFiles="@(LicenseSourceFiles)" DestinationFolder="$(BaseDir)\..\..\wwroot"></Copy>
        <Copy SourceFiles="@(RobotSourceFile)" DestinationFolder="$(BaseDir)\..\..\wwwroot"></Copy>

        <Message Text="Started deploying to test" />
        <Exec Command="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe ..\..\wwwroot\WebApp.csproj /property:Configuration=Test /t:MsDeployPublish /p:MsDeployServiceUrl=99.99.99.99;DeployIisAppPath=MySite;username=user;password=pass;allowuntrustedcertificate=true" />
        <Message Text="Finished deploying to test" />
    </Target>
</Project>

Now this should fix the problem if there is indeed a problem with the relative file paths.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top