Im trying to publish one of our web-projects with MSBuild. When I do it directly through VS 2017 it works fine but when I run MSBuild it fails.
MS Build command:
"C:\ProgramFiles(x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild" MySolution.sln /p:DeployOnbuild=true /p:Configuration=Release /p:PublishProfile=Properties/PublishProfiles/publish.pubxml
Results in the following error
C:\Program Files (x86)\Microsoft Visual
Studio\2017\BuildTools\MSBuild\Microsoft\VisualStudio\v15.0\Web\Microsoft.Web.Publishing.targets(4359,
4): PublishProfile(publish.pubxml) is set. But the $(WebPublishMethod)
does not have a valid value. Current Value is "FileSystem".
My publish.pubxml file looks like this
<?xml version="1.0" encoding="utf-8"?>
<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>\\1.1.1.1\c$\Site\mysite.se</publishUrl>
<DeleteExistingFiles>True</DeleteExistingFiles>
</PropertyGroup>
</Project>
What do I do wrong?
Related
I have a simple "Hello World" mvc web application that I am attempting to build in VSTS. My steps are:
Get Sources
Run msbuild on a single project
Publish artifact (publish directory)
Everything works fine whenever I use a profile for msbuild, but I would like to just pass the parameter commands in instead. When I do this I get the following error:
Error : Copying file bin\WebApp01.dll to obj\Release\Package\PackageTmp\bin\WebApp01.dll failed. Could not find file 'bin\WebApp01.dll'.
What mistake am I making with my msbuild parameters? How do I properly duplicate a simple file system profile?
Parameters (error'ing):
/p:DeployOnBuild=true /p:Configuration="Release" /p:Platform="Any CPU" /t:WebPublish /p:WebPublishMethod=FileSystem /p:publishUrl=PublishToOctopus
Profile (works):
<?xml version="1.0" encoding="utf-8"?>
<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>PublishToOctopus</publishUrl>
<DeleteExistingFiles>False</DeleteExistingFiles>
</PropertyGroup>
</Project>
When using /p:DeployOnBuild=true, you can use the normal Build target. You directly called WebPublish (/t:WebPublish) which expects a build to already have happened but since it doesn't, the file is missing from the expected location.
In Visual Studio 2017 when publishing an Asp.Net Core Website using the File System publish method I want to trigger the execution of a .bat file after the publish operation copied the files to the output directory.
I have learned that the settings for the publish operation are stored by Visual Studio in the project's Properties/PublishProviles directory in a .pubxml file. So in may case the file is FolderProfile.pubxml and it currently looks like this:
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<PublishProvider>FileSystem</PublishProvider>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>False</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<PublishFramework>net461</PublishFramework>
<ProjectGuid>f58b5ca0-8221-4c97-aa6d-7fba93a3abeb</ProjectGuid>
<publishUrl>C:\inetpub\wwwGiftOasisResponsivePublished</publishUrl>
<DeleteExistingFiles>True</DeleteExistingFiles>
</PropertyGroup>
</Project>
Based on the comments in the .pubxml file and additional research, it's my understanding this file is essentially an msbuild file and ultimately msbuild is used to perform the publish operation. msbuild files seem very flexible but more than a little complicated. I'm really struggling with this one.
If I had a batch file in the root of my project called finishPub.bat, how could I modify the above .pubxml file to cause the execute of the finishPub.bat file after the website has been copied to the output folder?
You can amend your publish profile with a custom target:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
...
</PropertyGroup>
<Target Name="ExecuteBatAfterPublish" AfterTargets="AfterPublish">
<Exec Command="example.bat" WorkingDirectory="$(publishUrl)" />
</Target>
</Project>
I want to build a *.appxbundle for a Windows 8.1 JavaScript app which contains the x86 AND x64 appx.
This is working fine on Visual Studio 2013. I right click on the project and choose Store->Create app packages and then pick both architectures.
However I can't get it working on MSBuild. My msbuild statement looks like this:
msbuild MyProj.Win81.jsproj /property:Configuration=Release;Platform=x64;AppxBundle=Always /target:Clean,Rebuild,Publish
My MyProj.Win81.jsproj looks like this (shortened a bit):
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ProjectConfiguration Include="Debug|AnyCPU">
<Configuration>Debug</Configuration>
<Platform>AnyCPU</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|ARM">
<Configuration>Debug</Configuration>
<Platform>ARM</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x86">
<Configuration>Debug</Configuration>
<Platform>x86</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|AnyCPU">
<Configuration>Release</Configuration>
<Platform>AnyCPU</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|ARM">
<Configuration>Release</Configuration>
<Platform>ARM</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x86">
<Configuration>Release</Configuration>
<Platform>x86</Platform>
</ProjectConfiguration>
</ItemGroup>
<Import Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
<PropertyGroup Condition="'$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '12.0'">
<VisualStudioVersion>12.0</VisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\$(WMSJSProjectDirectory)\Microsoft.VisualStudio.$(WMSJSProject).Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\$(WMSJSProjectDirectory)\Microsoft.VisualStudio.$(WMSJSProject).props" />
<PropertyGroup>
<TargetPlatformIdentifier>Windows</TargetPlatformIdentifier>
<TargetPlatformVersion>8.1</TargetPlatformVersion>
<RequiredPlatformVersion>8.1</RequiredPlatformVersion>
<MinimumVisualStudioVersion>12.0</MinimumVisualStudioVersion>
<DefaultLanguage>en-US</DefaultLanguage>
<AppxAutoIncrementPackageRevision>False</AppxAutoIncrementPackageRevision>
<AppxBundle>Always</AppxBundle>
<AppxBundlePlatforms>x86|x64</AppxBundlePlatforms>
</PropertyGroup>
<ItemGroup>
<AppxManifest Include="package.win81.store.appxmanifest">
<SubType>Designer</SubType>
</AppxManifest>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\$(WMSJSProjectDirectory)\Microsoft.VisualStudio.$(WMSJSProject).targets" />
</Project>
MSBuild will always generate a appxbundle which only includes the x64 architecture. This might be because I explicitly set Platform=x64, although AppxBundlePlatforms defines both. If I leave out the Platform parameter I run into a error:
error APPX3104: You cannot create an app bundle when building for platform 'AnyCPU' which is not included in the list of platforms selected for producting app bundle. Set platform to a one of following values: x86;x64.
What am I missing?
// edit: here a screenshot of VS2013 appxbundle creation and updated project configuration of jsproj file
In the following simple MSBuild file I'd like to overwrite the output path that is defined in the .sln or .csproj file. In line 13 you can see that I call an MSBuild task for an existing VS solution. Usually, the projects that are part of that solution have a property where the output is stored. With my script I'd like to overwrite that so that my "build automation" uses a different directory than the default one.
<Project
xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
DefaultTargets="Default">
<PropertyGroup>
<appname>Some App</appname>
<version>2.9.1</version>
<file_xap>Some.App.WP8_$(version).$([System.DateTime]::Now.ToString(`yyyyMMddHHmmss`)).xap</file_xap>
</PropertyGroup>
<Target Name="Default">
<MSBuild Projects="C:\Users\User\Documents\Visual Studio 2013\Projects\SomeApp\SomeApp.sln" Properties="Configuration=Debug;Platform=Any CPU">
</MSBuild>
<Message Text="Output file: $(file_xap)"/>
</Target>
</Project>
So the actual question is: How can I call MSBuild for that sln in a way that the output (the xap-file in that case) to another directory (having all the output apart from the xap-file is fine as well)?
I will post my full xml here so you can understand it all
the structure of the project is like this:
MyProject----MyProject.sln
----MyProject.Server---
----MyProject.Server.proj
----Other server project classes and stuff
----MyProject.Client---
----MyProject.Client.proj
----Client project related stuff
----BuildFromXmlFldr---
----build_both_proj.xml <---This is the example file i posted here
Here is the build_both_proj.xml
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
ToolsVersion="4.0"
DefaultTargets="Build">
<PropertyGroup>
<SolutionDir>..\</SolutionDir>
<ServerProjectFile>..\MyProject.Server\MyProject.Server.csproj</ServerProjectFile>
<ClientProjectFile>..\MyProject.Client\MyProject.Client.csproj</ClientProjectFile>
<ServerProjectName>MyProject.Server</ServerProjectName>
<ClientProjectName>MyProject.Client</ClientProjectName>
<ServerOutput>C:\_Publish\Server\</ServerOutput>
<ClientOutput>C:\_Publish\Client\</ClientOutput>
<Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
</PropertyGroup>
<Target Name="BuildServer">
<MSBuild Projects="$(ServerProjectFile)"
Targets="Build"
Properties="Configuration=$(Configuration);Platform=$(Platform);OutputPath=$(ServerOutput);">
</MSBuild>
</Target>
<Target Name="BuildClient">
<MSBuild Projects="$(ClientProjectFile)"
Targets="Build"
Properties="Configuration=$(Configuration);Platform=$(Platform);OutputPath=$(ClientOutput);"
StopOnFirstFailure="true">
</MSBuild>
</Target>
<PropertyGroup>
<BuildAllDependsOn>BuildServer;BuildClient</BuildAllDependsOn>
</PropertyGroup>
<Target Name="BuildAll" DependsOnTargets="$(BuildAllDependsOn)"/>
</Project>
This is the msbuild.exe command inside the folder BuildFromXmlFldr that I used:
c:\path_to_msbuild\MSBuild.exe build_both_proj.xml /t:BuildAll
so the output is determined in the Properties attribute in the Target tag
Properties="Configuration=$(Configuration);Platform=$(Platform);OutputPath=$(ServerOutput);"
I have a .vcxproj file that compiles a C++ program. I would like to create a second MSBuild project file that tests the program by running it, but only if the program has been rebuilt since the last successful test. How can I access the "TargetPath" of the program from the second project file?
If I could access TargetPath as an "item" from the .vcxproj file, then the the tester project file will look like this:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Build" Inputs="#(TargetPath)" Outputs="#(TargetPath->'%(filename).test-passed)'">
<Exec Command="#(TargetPath)" />
<Touch Files="#(TargetPath->'%(filename).test-passed)'" />
</Target>
</Project>
I would like to execute the test using a separate project file from the compilation of the program, to make it easier to choose between build-and-test or build-and-debug within Visual Studio, without multiplying the build configurations.
It is possible to run a native program compiled by a separate .vcxproj using the MSBuild task. Use the <Output> element to create an Item with the "TargetOutputs" from the C++ application build. However, if you are building a "native" program, "TargetOutputs" is normally blank. In this case, use the "GetNativeTargetPath" target to get the output path. The following project .vcxproj file works with Visual Studio. It builds test_build.vcxproj. The test_build.exe file is run, if it has changed since the last successful run.
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{80DB0D71-72E0-4FB1-B53F-EFB858A1D5A8}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>nordic_test_run</RootNamespace>
</PropertyGroup>
<PropertyGroup>
<ConfigurationType>Application</ConfigurationType>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ItemGroup>
<ProjectReference Include="test_build.vcxproj" />
</ItemGroup>
<Target Name="BuildExecutable">
<MSBuild Projects="#(ProjectReference)" Targets="Build" BuildInParallel="True" />
<MSBuild Projects="#(ProjectReference)" Targets="GetNativeTargetPath" BuildInParallel="True">
<Output TaskParameter="TargetOutputs" ItemName="NativeTests" />
</MSBuild>
</Target>
<Target Name="Build" DependsOnTargets="BuildExecutable" Inputs="#(NativeTests)" Outputs="#(NativeTests->'%(filename).test-passed')">
<Exec Command="#(NativeTests)" />
<Touch Files="#(TestTargets->'%(filename).test-passed')" />
</Target>
</Project>