Something like
msbuild /t:publish [use PublishProfileName] someproject.csproj
msbuild MyProject.csproj /t:PipelinePreDeployCopyAllFilesToOneFolder /p:Configuration=Release;_PackageTempDir=C:\temp\somelocation;AutoParameterizationWebConfigConnectionStrings=false
See MSBuild 2010 - how to publish web app to a specific location (nant)?
For Visual Studio 2012 you can use
msbuild MySolution.sln /p:DeployOnBuild=true;PublishProfile=Production;Password=foo
See ASP.NET Web Deployment using Visual Studio: Command Line Deployment
This is an alternative solution for achieving Pavel's solution but using MsBuild target in a MsBuild file:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration>
<OutputDirectory>$(DeploymentProject)\bin\$(Configuration)</OutputDirectory>
<OutputPath>C:\Inetpub\wwwroot</OutputPath>
</PropertyGroup>
<Target Name="build">
<MSBuild
Projects="Your Solution File.sln"
Properties="Configuration=$(Configuration);DeployOnBuild=true;DeployTarget=Package;_PackageTempDir=$(OutputPath);AutoParameterizationWebConfigConnectionStrings=false"
>
</MSBuild>
</Target>
</Project>
Related
I am trying to publish my asp.net-core app via command line and use the "PublishedTrimmed" functionality.
I tried this both via
dotnet build -c Release './project.csproj' /p:DeployOnBuild=true /p:PublishProfile=FolderProfile
and
dotnet publish -c Release './project.csproj' -o "outputPath"
The publish profile used in the build command looks like this:
<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>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>True</ExcludeApp_Data>
<ProjectGuid>1b763e24-74f7-453c-bf79-210861cd0fd7</ProjectGuid>
<publishUrl>[redacted]</publishUrl>
<DeleteExistingFiles>True</DeleteExistingFiles>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
<PublishSingleFile>False</PublishSingleFile>
<PublishTrimmed>True</PublishTrimmed>
<SelfContained>true</SelfContained>
</PropertyGroup>
</Project>
To use the publish command i added the relevant code to the csproj file as follows:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>
<PublishSingleFile>True</PublishSingleFile>
<PublishTrimmed>True</PublishTrimmed>
</PropertyGroup>
</Project>
Sadly all tries i made resulted in the same error:
C:\Program Files\dotnet\sdk\3.1.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ILLink.targets(83,5): error MSB6006: "dotnet.exe" has exited with error code -532462766.
This also happens if I use built in publish button in Visual Studio 2019
I have currently only the v.3.1.101 (x64) .net-core SDK installed and it builds and publishes correctly when not using 'PublishTrimmed'
The error message isn't really helping me much, so can anyone tell me why this error occurs and how to solve the problem?
Thanks!
I created a Directory.Build.props file, with VersionSuffix contain the current Hour and Minutes:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VersionSuffix>$([System.DateTime]::Now.ToString(yyyy-MM-dd-HHmm))-$(Configuration)</VersionSuffix>
</PropertyGroup>
</Project>
Now, because this file changed every minute, the Visual Studio complete it auto-restore, and start it again, because after a minute the properties are different.
So, I added a Target to update the properties only before the Build:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Version" BeforeTargets="Build">
<PropertyGroup>
<VersionSuffix>$([System.DateTime]::Now.ToString(yyyy-MM-dd-HHmm))-$(Configuration)</VersionSuffix>
</PropertyGroup>
</Target>
</Project>
Now the Visual Studio works fine, but from the command-line (msbuild MySln.sln /t:Build...) the properties don't apply.
(I tried with Directory.Build.targets and it acts the same (unless I missed something))
(You can try with more simple property, Company for example).
How can I use a time-based property, but apply it only when I creating the DLL?
Using InitialTargets solved my problem:
<Project InitialTargets="Version" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Version">
<PropertyGroup>
<VersionSuffix>$([System.DateTime]::Now.ToString(yyyy-MM-dd-HHmm))-$(Configuration)</VersionSuffix>
</PropertyGroup>
</Target>
</Project>
I'm trying to apply custom ACLs using webdeploy (set Write permission to a folder - the folder is empty but added to the project and correctly deployed).
I'm building a VS solution on my CI server with the following command line:
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\msbuild.exe"
/consoleloggerparameters:ErrorsOnly
/maxcpucount
/nologo
/property:Configuration=Release
/p:Platform=x86
/verbosity:quiet
MySolution.sln
/p:DeployOnBuild=True
/p:PublishProfile="ci"
/p:ProfileTransformWebConfigEnabled=False
/p:WebPublishPipelineCustomizeTargetFile="MyProject\MyProject.wpp.targets"
It builds correctly but it completely ignores the content of my MyProject.wpp.targets. I tried to write wrong XML but it gets silently ignored, the build is successful but clearly without my wpp.targets applied. The /p:WebPublishPipelineCustomizeTargetFile parameter doesn't have any effect.
This is the content of MyProject.wpp.targets:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="SetupCustomAcls" AfterTargets="AddIisSettingAndFileContentsToSourceManifest">
<ItemGroup>
<MsDeploySourceManifest Include="setAcl">
<Path>$(_MSDeployDirPath_FullPath)\Content\cache</Path>
<setAclAccess>Read,Write</setAclAccess>
<setAclResourceType>Directory</setAclResourceType>
<AdditionalProviderSettings>setAclResourceType;setAclAccess</AdditionalProviderSettings>
</MsDeploySourceManifest>
</ItemGroup>
</Target>
<Target Name="DeclareCustomParameters" AfterTargets="AddIisAndContentDeclareParametersItems">
<ItemGroup>
<MsDeployDeclareParameters Include="ContentCacheSetAclParam">
<Kind>ProviderPath</Kind>
<Scope>setAcl</Scope>
<Match>^$(_EscapeRegEx_MSDeployDirPath)\\Content\\cache$</Match>
<Description>Add write permission to the Content/cache folder.</Description>
<DefaultValue>{$(_MsDeployParameterNameForContentPath)}/Content/cache</DefaultValue>
<Value>$(_DestinationContentPath)/Content/cache</Value>
<Tags>Hidden</Tags>
<Priority>$(VsSetAclPriority)</Priority>
<ExcludeFromSetParameter>True</ExcludeFromSetParameter>
</MsDeployDeclareParameters>
</ItemGroup>
</Target>
</Project>
The project is a net641 csproj <Project Sdk="Microsoft.NET.Sdk.Web">.
What's wrong with my configuration? Thank you for your help.
I have a WebSite which is locally in a folder on my computer. It doesn't have a .csproj - just all the files in a folder. I want to do the publish website in the automated build which is basically as doing it in command line using msbuild.exe and\or msdeploy.exe and\or aspnet_compiler.exe and/or anything else.
If you want to create a project like so you can create an empty solution, add -> new website (select filesystem on the buttom in the combobox), add an empty class file, right click on the website line in the solution explorer, under the solution line, Publish website, there you need to create a new profile- really easy- basically choosing "file-system" and then publish.
I'm running on VS2012, update 4.
if you pass in an MSbuild argument of
/p:DeployOnBuild=true;PublishProfile=PROFILENAME
it should do the same as publishing from VS if your profile is set up correctly
EDIT
Sorry just had to run one of these through to see what happens
when you check in a Website to TFS it creates a websites folder.
you can then map your build to this folder.
instead of mapping the build to a sln file you can point to the publishproj file, this gets created when you create the publish profile. this tells the build what to do
in this i had set the publish location to be c:\publish and after the build i had the output in a folder called c:\publish.
the generated publishproj file looks like this
<?xml version="1.0" encoding="utf-8"?>
<!--
***********************************************************************************************
website.publishproj
WARNING: DO NOT MODIFY this file, it is used for the web publish process.
Copyright (C) Microsoft Corporation. All rights reserved.
***********************************************************************************************
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>10.0.30319</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{f17a9da4-9b68-41e4-ab73-5ac72898b384}</ProjectGuid>
<SourceWebPhysicalPath>$(MSBuildThisFileDirectory)</SourceWebPhysicalPath>
<SourceWebVirtualPath>/WebSite1</SourceWebVirtualPath>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<SourceWebProject>http://localhost:61874</SourceWebProject>
<SourceWebMetabasePath>/IISExpress/7.5/LM/W3SVC/15/ROOT</SourceWebMetabasePath>
</PropertyGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<!-- for VS2010 we need to use 10.5 but for VS2012+ we should use VisualStudioVersion -->
<WebPublishTargetsVersion Condition=" '$(WebPublishTargetsVersion)' =='' and '$(VisualStudioVersion)' == 10.0 ">10.5</WebPublishTargetsVersion>
<WebPublishTargetsVersion Condition=" '$(WebPublishTargetsVersion)'=='' ">$(VisualStudioVersion)</WebPublishTargetsVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(WebPublishTargetsVersion)</VSToolsPath>
<_WebPublishTargetsPath Condition=" '$(_WebPublishTargetsPath)'=='' ">$(VSToolsPath)</_WebPublishTargetsPath>
<AssemblyFileVersion Condition="'$(AssemblyFileVersion)' == ''">1.0.0.0</AssemblyFileVersion>
<AssemblyVersion Condition="'$(AssemblyVersion)' == ''">1.0.0.0</AssemblyVersion>
</PropertyGroup>
<ItemGroup>
<AssemblyAttributes Include="AssemblyFileVersion">
<Value>$(AssemblyFileVersion)</Value>
</AssemblyAttributes>
<AssemblyAttributes Include="AssemblyVersion">
<Value>$(AssemblyVersion)</Value>
</AssemblyAttributes>
</ItemGroup>
<Import Project="$(_WebPublishTargetsPath)\Web\Microsoft.WebSite.Publishing.targets" />
</Project>
I am trying to build web application and copy the output to build\bin\debug folder in the root. But the folder structure is getting created for every project that is referenced in the web application. I need output of web application and all referenced dll's in the root folder.
<?xml version="1.0" encoding="utf-8" ?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<BuildDir>build\bin\$(BuildConfig)</BuildDir>
<BuildConfig>Debug</BuildConfig>
</PropertyGroup>
<ItemGroup>
<ProjectToBuild Include="testwebapp.sln">
<Properties>OutputPath=$(BuildDir);Configuration=$(BuildConfig)</Properties>
</ProjectToBuild>
</ItemGroup>
<Target Name="Build">
<Message Text="Building solution..."/>
<MSBuild Projects="#(ProjectToBuild)" Targets="Build">
</MSBuild>
</Target>
</Project>
But it is working if I execute it using command line prompt like
msbuild "testwebapp.sln" /t:build /p:OutputPath="custompath"
Properties evaluate in order so your
<BuildDir>build\bin\$(BuildConfig)</BuildDir>
<BuildConfig>Debug</BuildConfig>
should be
<BuildConfig>Debug</BuildConfig>
<BuildDir>build\bin\$(BuildConfig)</BuildDir>