In .csproj file is set:
<PropertyGroup>
<Company>Acme</Company>
<Product>NextBigThing</Product>
</PropertyGroup>
I would like use variables in following Post-Build-Event:
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="xcopy <source> %AppData%\<Company>\<Product>\" />
</Target>
How to use Company and Product variable as part of path in Post-Build-Event?
My solution using PowerShell 7
You need to create a PowerShell script inside of project folder, for this example is "PostBuild.ps1". This script will be called in PostbuildEvents property.
For MsBuild properties
https://learn.microsoft.com/es-es/visualstudio/ide/how-to-specify-build-events-csharp?view=vs-2022
Download Powershell
https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows?view=powershell-7.3
First Solution Reading the Project'XML and retrieving the properties.
Your project files
Your project XML
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Company>Acme</Company>
<Product>NextBigThing</Product>
</PropertyGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="pwsh -NoLogo -ExecutionPolicy Bypass -Command "./PostBuild.ps1 -ProjectFileName $(ProjectFileName)"" />
</Target>
</Project>
Your project properties - Visual studio
The command to call "PostBuild.ps1" is
pwsh -NoLogo -ExecutionPolicy Bypass -Command "./PostBuild.ps1 -ProjectFileName $(ProjectFileName)"
PostBuild.ps1 - Code
[CmdletBinding()]
param (
[Parameter()]
[string]
$ProjectFileName
)
Write-Host "█ ProjectFileName from parameters: $ProjectFileName"
$basePath = "//Project/PropertyGroup"
$companyLabel = "Company"
$productLabel = "Product"
if (!(Test-Path $ProjectFileName -PathType Leaf) -or (!"$ProjectFileName".EndsWith(".csproj"))) {
throw "Invalid file `"$ProjectFileName`"."
}
[System.Xml.XmlDocument] $doc = [System.Xml.XmlDocument]::new()
$doc.PreserveWhitespace = $true
$doc.Load($ProjectFilename)
$company = $doc.DocumentElement.SelectSingleNode("$basePath/$companyLabel").InnerText
$product = $doc.DocumentElement.SelectSingleNode("$basePath/$productLabel").InnerText
Write-Host "█ command: xcopy ""$PSScriptRoot"" ""%AppData%\$company\$product\"""
Output
1>------ Rebuild All started: Project: VariablesInPostBuildEvents, Configuration: Debug Any CPU ------
Restored C:\Users\Megam\Desktop\so an\VariablesInPostBuildEvents\VariablesInPostBuildEvents.csproj (in 3 ms).
1>VariablesInPostBuildEvents -> C:\Users\Megam\Desktop\so an\VariablesInPostBuildEvents\bin\Debug\net7.0\VariablesInPostBuildEvents.dll
1>█ ProjectFileName from parameters: VariablesInPostBuildEvents.csproj
1>█ command: xcopy "C:\Users\Megam\Desktop\so an\VariablesInPostBuildEvents" "%AppData%\Acme\NextBigThing\"
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
========== Elapsed 00:01.628 ==========
Second Solution Company and Product are MSBuild known properties. It can be included in command.
Same file structure
Command in PostBuildEvents
pwsh -NoLogo -ExecutionPolicy Bypass -Command "./PostBuild.ps1 -Company $(Company) -Product $(Product)"
PostBuild.ps1
[CmdletBinding()]
param (
[Parameter()]
[string]
$Company,
[Parameter()]
[string]
$Product
)
Write-Host "█ Company: $Company"
Write-Host "█ Company: $Product"
Write-Host "█ command: xcopy ""$PSScriptRoot"" ""%AppData%\$company\$product\"""
Output
Rebuild started...
1>------ Rebuild All started: Project: VariablesInPostBuildEvents, Configuration: Debug Any CPU ------
Restored C:\Users\Megam\Desktop\so an\VariablesInPostBuildEvents\VariablesInPostBuildEvents.csproj (in 2 ms).
1>VariablesInPostBuildEvents -> C:\Users\Megam\Desktop\so an\VariablesInPostBuildEvents\bin\Debug\net7.0\VariablesInPostBuildEvents.dll
1>█ Company: Acme
1>█ Company: NextBigThing
1>█ command: xcopy "C:\Users\Megam\Desktop\so an\VariablesInPostBuildEvents" "%AppData%\Acme\NextBigThing\"
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
========== Elapsed 00:02.728 ==========
Just use $(<VariableName>) like
<Exec Command="xcopy ... \$(Company)\$(Product)\ ..." />
based on https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-properties?view=vs-2022
Related
I'm doing a few shadereffects in a wpf_c# project and i don't know and i didn't find how to add the bytecode pixelshader (.ps) as Resource after be compiled by a target/exec. This is my csproj code fragment:
<ItemGroup>
<AvailableItemName Include="PixelShader"/>
</ItemGroup>
<ItemGroup>
<PixelShader Include="Shaders\BlueToneShader.fx" />
bla bla bla other shaders bla bla
</ItemGroup>
<Target Name="PixelShaderCompile" Condition="#(PixelShader)!=''" BeforeTargets="Build">
<Exec Command=""C:\Program Files (x86)\Windows Kits\10\bin\10.0.18362.0\x64\fxc.exe" %(PixelShader.Identity) /T ps_3_0 /E main /Fo%(PixelShader.RelativeDir)%(PixelShader.Filename).ps" />
</Target>
Everything goes fine and the .ps files are correctly generated, as example:
PixelShaderCompile:
"C:\Program Files (x86)\Windows Kits\10\bin\10.0.18362.0\x64\fxc.exe" Shaders\BlueToneShader.fx /T ps_3_0 /E main /FoShaders\BlueToneShader.ps
Microsoft (R) Direct3D Shader Compiler 10.1 Copyright (C) 2013 Microsoft. All rights reserved.
compilation object save succeeded; see "folder"...
But now i dont know how to add that .ps file as 'Resource' during the compilation. Any one knows how? I didn't find any clear documentation.
After 3-4 hours of trial-error i found a (i think dirty) way to do it: the msbuild (.csproj) looks like:
<PropertyGroup>
<BuildDependsOn>
PixelShaderCompile
$(BuildDependsOn)
</BuildDependsOn>
</PropertyGroup>
<ItemGroup>
<AvailableItemName Include="PixelShader">
<Visible>true</Visible>
</AvailableItemName>
</ItemGroup>
<ItemGroup>
<PixelShader ... />
...
</ItemGroup>
<Target Name="PixelShaderCompile" Condition="#(PixelShader)!=''" BeforeTargets="BeforeBuild;BeforeRebuild">
<MakeDir Directories="$(IntermediateOutputPath)%(PixelShader.RelativeDir)" Condition="!Exists('$(IntermediateOutputPath)%(PixelShader.RelativeDir)')" />
//You put your fxc.exe command here
<Exec Command=""C:\bla bla bla\fxc.exe" %(PixelShader.Identity) /T ps_3_0 /E PSmain /O3 /Fo$(IntermediateOutputPath)%(PixelShader.RelativeDir)%(PixelShader.Filename).ps" Outputs="$(IntermediateOutputPath)%(PixelShader.RelativeDir)%(PixelShader.Filename).ps">
<Output ItemName="CompiledPixelShader" TaskParameter="Outputs" />
</Exec>
<ItemGroup>
<Resource Include="#(CompiledPixelShader)" />
</ItemGroup>
</Target>
//If you want to clear the .ps generated file
<Target Name="PixelShaderClean" Condition="#(PixelShader)!=''" AfterTargets="AfterBuild;AfterRebuild">
<Delete Files="$(IntermediateOutputPath)%(PixelShader.RelativeDir)%(PixelShader.Filename).ps" />
</Target>
That's it... So hard because there aren't so many made examples of msbuild files.
I am trying to publish my web app as an IIS package. This is my publish configuration, generated through the GUI wizard:
<?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>Package</WebPublishMethod>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<TargetFramework>netcoreapp1.1</TargetFramework>
<ProjectGuid>d1420173-e5a3-4446-a494-61de03f28b4f</ProjectGuid>
<DesktopBuildPackageLocation>project-name.zip</DesktopBuildPackageLocation>
<PackageAsSingleFile>true</PackageAsSingleFile>
<DeployIisAppPath>TestDozor/Dozor</DeployIisAppPath>
<PublishDatabaseSettings>
<Objects xmlns="" />
</PublishDatabaseSettings>
</PropertyGroup>
</Project>
And this is what I see when I try to publish:
1>------ Build started: Project: project-name, Configuration: Release Any CPU ------
1>project-name -> D:\ ... \project-name\bin\Release\netcoreapp1.1\project-name.dll
2>------ Publish started: Project: project-name, Configuration: Release Any CPU ------
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Roslyn\csc.exe /noconfig /unsafe- /checked- /nowarn:1701,1702,1705,2008 /nostdlib+ /errorreport:prompt /warn:4 /define:TRACE;RELEASE;NETCOREAPP1_1 /main:dozor_backend.Program /errorendlocation /preferreduilang:cs-CZ /reference:C:\Users\mareda\.nuget\packages\microsoft.applicationinsights.aspnetcore\2.0.0\lib\netstandard1.6\Microsoft.ApplicationInsights.AspNetCore.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.applicationinsights\2.2.0\lib\netstandard1.5\Microsoft.ApplicationInsights.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.aspnetcore.diagnostics.abstractions\1.1.2\lib\netstandard1.0\Microsoft.AspNetCore.Diagnostics.Abstractions.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.aspnetcore.diagnostics\1.1.2\lib\netstandard1.3\Microsoft.AspNetCore.Diagnostics.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.aspnetcore.hosting.abstractions\1.1.2\lib\netstandard1.3\Microsoft.AspNetCore.Hosting.Abstractions.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.aspnetcore.hosting\1.1.2\lib\netstandard1.5\Microsoft.AspNetCore.Hosting.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.aspnetcore.hosting.server.abstractions\1.1.2\lib\netstandard1.3\Microsoft.AspNetCore.Hosting.Server.Abstractions.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.aspnetcore.http.abstractions\1.1.2\lib\netstandard1.3\Microsoft.AspNetCore.Http.Abstractions.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.aspnetcore.http\1.1.2\lib\netstandard1.3\Microsoft.AspNetCore.Http.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.aspnetcore.http.extensions\1.1.2\lib\netstandard1.3\Microsoft.AspNetCore.Http.Extensions.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.aspnetcore.http.features\1.1.2\lib\netstandard1.3\Microsoft.AspNetCore.Http.Features.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.aspnetcore.httpoverrides\1.1.2\lib\netstandard1.3\Microsoft.AspNetCore.HttpOverrides.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.aspnetcore.routing.abstractions\1.1.2\lib\netstandard1.3\Microsoft.AspNetCore.Routing.Abstractions.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.aspnetcore.routing\1.1.2\lib\netstandard1.3\Microsoft.AspNetCore.Routing.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.aspnetcore.server.iisintegration\1.1.2\lib\netstandard1.3\Microsoft.AspNetCore.Server.IISIntegration.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.aspnetcore.server.kestrel\1.1.2\lib\netstandard1.3\Microsoft.AspNetCore.Server.Kestrel.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.aspnetcore.staticfilesex\1.0.0.4\lib\netstandard1.3\Microsoft.AspNetCore.StaticFilesEx.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.aspnetcore.webutilities\1.1.2\lib\netstandard1.3\Microsoft.AspNetCore.WebUtilities.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.csharp\4.3.0\ref\netstandard1.0\Microsoft.CSharp.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.extensions.configuration.abstractions\1.1.2\lib\netstandard1.0\Microsoft.Extensions.Configuration.Abstractions.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.extensions.configuration.binder\1.1.2\lib\netstandard1.1\Microsoft.Extensions.Configuration.Binder.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.extensions.configuration\1.1.2\lib\netstandard1.1\Microsoft.Extensions.Configuration.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.extensions.configuration.environmentvariables\1.1.2\lib\netstandard1.3\Microsoft.Extensions.Configuration.EnvironmentVariables.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.extensions.configuration.fileextensions\1.1.2\lib\netstandard1.3\Microsoft.Extensions.Configuration.FileExtensions.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.extensions.configuration.json\1.1.2\lib\netstandard1.3\Microsoft.Extensions.Configuration.Json.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.extensions.dependencyinjection.abstractions\1.1.1\lib\netstandard1.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.extensions.dependencyinjection\1.1.1\lib\netstandard1.1\Microsoft.Extensions.DependencyInjection.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.extensions.diagnosticadapter\1.0.0\lib\netstandard1.1\Microsoft.Extensions.DiagnosticAdapter.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.extensions.fileproviders.abstractions\1.1.1\lib\netstandard1.0\Microsoft.Extensions.FileProviders.Abstractions.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.extensions.fileproviders.physical\1.1.1\lib\netstandard1.3\Microsoft.Extensions.FileProviders.Physical.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.extensions.filesystemglobbing\1.1.1\lib\netstandard1.3\Microsoft.Extensions.FileSystemGlobbing.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.extensions.logging.abstractions\1.1.2\lib\netstandard1.1\Microsoft.Extensions.Logging.Abstractions.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.extensions.logging.console\1.1.2\lib\netstandard1.3\Microsoft.Extensions.Logging.Console.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.extensions.logging\1.1.2\lib\netstandard1.1\Microsoft.Extensions.Logging.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.extensions.objectpool\1.1.1\lib\netstandard1.3\Microsoft.Extensions.ObjectPool.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.extensions.options.configurationextensions\1.1.2\lib\netstandard1.1\Microsoft.Extensions.Options.ConfigurationExtensions.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.extensions.options\1.1.2\lib\netstandard1.0\Microsoft.Extensions.Options.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.extensions.platformabstractions\1.1.0\lib\netstandard1.3\Microsoft.Extensions.PlatformAbstractions.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.extensions.primitives\1.1.1\lib\netstandard1.0\Microsoft.Extensions.Primitives.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.extensions.webencoders\1.0.0\lib\netstandard1.0\Microsoft.Extensions.WebEncoders.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.net.http.headers\1.1.2\lib\netstandard1.1\Microsoft.Net.Http.Headers.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.visualbasic\10.1.0\ref\netstandard1.1\Microsoft.VisualBasic.dll /reference:C:\Users\mareda\.nuget\packages\microsoft.win32.primitives\4.3.0\ref\netstandard1.3\Microsoft.Win32.Primitives.dll /reference:C:\Users\mareda\.nuget\packages\msa.netcore.odbc\1.0.3\lib\netstandard1.6\NetCoreODBC.dll /reference:C:\Users\mareda\.nuget\packages\newtonsoft.json\10.0.3\lib\netstandard1.3\Newtonsoft.Json.dll /reference:C:\Users\mareda\.nuget\packages\system.appcontext\4.3.0\ref\netstandard1.6\System.AppContext.dll /reference:C:\Users\mareda\.nuget\packages\system.buffers\4.3.0\lib\netstandard1.1\System.Buffers.dll /reference:C:\Users\mareda\.nuget\packages\system.collections.concurrent\4.3.0\ref\netstandard1.3\System.Collections.Concurrent.dll /reference:C:\Users\mareda\.nuget\packages\system.collections\4.3.0\ref\netstandard1.3\System.Collections.dll /reference:C:\Users\mareda\.nuget\packages\system.collections.immutable\1.3.0\lib\netstandard1.0\System.Collections.Immutable.dll /reference:C:\Users\mareda\.nuget\packages\system.collections.nongeneric\4.3.0\ref\netstandard1.3\System.Collections.NonGeneric.dll /reference:C:\Users\mareda\.nuget\packages\system.componentmodel.annotations\4.3.0\ref\netstandard1.4\System.ComponentModel.Annotations.dll /reference:C:\Users\mareda\.nuget\packages\system.componentmodel\4.3.0\ref\netstandard1.0\System.ComponentModel.dll /reference:C:\Users\mareda\.nuget\packages\system.componentmodel.primitives\4.3.0\ref\netstandard1.0\System.ComponentModel.Primitives.dll /reference:C:\Users\mareda\.nuget\packages\system.componentmodel.typeconverter\4.3.0\ref\netstandard1.5\System.ComponentModel.TypeConverter.dll /reference:C:\Users\mareda\.nuget\packages\system.console\4.3.0\ref\netstandard1.3\System.Console.dll /reference:C:\Users\mareda\.nuget\packages\system.data.common\4.3.0\ref\netstandard1.2\System.Data.Common.dll /reference:C:\Users\mareda\.nuget\packages\system.diagnostics.contracts\4.3.0\ref\netstandard1.0\System.Diagnostics.Contracts.dll /reference:C:\Users\mareda\.nuget\packages\system.diagnostics.debug\4.3.0\ref\netstandard1.3\System.Diagnostics.Debug.dll /reference:C:\Users\mareda\.nuget\packages\system.diagnostics.diagnosticsource\4.3.1\lib\netstandard1.3\System.Diagnostics.DiagnosticSource.dll /reference:C:\Users\mareda\.nuget\packages\system.diagnostics.process\4.3.0\ref\netstandard1.4\System.Diagnostics.Process.dll /reference:C:\Users\mareda\.nuget\packages\system.diagnostics.stacktrace\4.3.0\ref\netstandard1.3\System.Diagnostics.StackTrace.dll /reference:C:\Users\mareda\.nuget\packages\system.diagnostics.tools\4.3.0\ref\netstandard1.0\System.Diagnostics.Tools.dll /reference:C:\Users\mareda\.nuget\packages\system.diagnostics.tracing\4.3.0\ref\netstandard1.5\System.Diagnostics.Tracing.dll /reference:C:\Users\mareda\.nuget\packages\system.dynamic.runtime\4.3.0\ref\netstandard1.3\System.Dynamic.Runtime.dll /reference:C:\Users\mareda\.nuget\packages\system.globalization.calendars\4.3.0\ref\netstandard1.3\System.Globalization.Calendars.dll /reference:C:\Users\mareda\.nuget\packages\system.globalization\4.3.0\ref\netstandard1.3\System.Globalization.dll /reference:C:\Users\mareda\.nuget\packages\system.globalization.extensions\4.3.0\ref\netstandard1.3\System.Globalization.Extensions.dll /reference:C:\Users\mareda\.nuget\packages\system.io.compression\4.3.0\ref\netstandard1.3\System.IO.Compression.dll /reference:C:\Users\mareda\.nuget\packages\system.io.compression.zipfile\4.3.0\ref\netstandard1.3\System.IO.Compression.ZipFile.dll /reference:C:\Users\mareda\.nuget\packages\system.io\4.3.0\ref\netstandard1.5\System.IO.dll /reference:C:\Users\mareda\.nuget\packages\system.io.filesystem\4.3.0\ref\netstandard1.3\System.IO.FileSystem.dll /reference:C:\Users\mareda\.nuget\packages\system.io.filesystem.primitives\4.3.0\ref\netstandard1.3\System.IO.FileSystem.Primitives.dll /reference:C:\Users\mareda\.nuget\packages\system.io.filesystem.watcher\4.3.0\ref\netstandard1.3\System.IO.FileSystem.Watcher.dll /reference:C:\Users\mareda\.nuget\packages\system.io.memorymappedfiles\4.3.0\ref\netstandard1.3\System.IO.MemoryMappedFiles.dll /reference:C:\Users\mareda\.nuget\packages\system.io.unmanagedmemorystream\4.3.0\ref\netstandard1.3\System.IO.UnmanagedMemoryStream.dll /reference:C:\Users\mareda\.nuget\packages\system.linq\4.3.0\ref\netstandard1.6\System.Linq.dll /reference:C:\Users\mareda\.nuget\packages\system.linq.expressions\4.3.0\ref\netstandard1.6\System.Linq.Expressions.dll /reference:C:\Users\mareda\.nuget\packages\system.linq.parallel\4.3.0\ref\netstandard1.1\System.Linq.Parallel.dll /reference:C:\Users\mareda\.nuget\packages\system.linq.queryable\4.3.0\ref\netstandard1.0\System.Linq.Queryable.dll /reference:C:\Users\mareda\.nuget\packages\system.net.http\4.3.2\ref\netstandard1.3\System.Net.Http.dll /reference:C:\Users\mareda\.nuget\packages\system.net.nameresolution\4.3.0\ref\netstandard1.3\System.Net.NameResolution.dll /reference:C:\Users\mareda\.nuget\packages\system.net.primitives\4.3.0\ref\netstandard1.3\System.Net.Primitives.dll /reference:C:\Users\mareda\.nuget\packages\system.net.requests\4.3.0\ref\netstandard1.3\System.Net.Requests.dll /reference:C:\Users\mareda\.nuget\packages\system.net.security\4.3.1\ref\netstandard1.3\System.Net.Security.dll /reference:C:\Users\mareda\.nuget\packages\system.net.sockets\4.3.0\ref\netstandard1.3\System.Net.Sockets.dll /reference:C:\Users\mareda\.nuget\packages\system.net.webheadercollection\4.3.0\ref\netstandard1.3\System.Net.WebHeaderCollection.dll /reference:C:\Users\mareda\.nuget\packages\system.net.websockets\4.3.0\ref\netstandard1.3\System.Net.WebSockets.dll /reference:C:\Users\mareda\.nuget\packages\system.numerics.vectors\4.3.0\ref\netstandard1.0\System.Numerics.Vectors.dll /reference:C:\Users\mareda\.nuget\packages\system.objectmodel\4.3.0\ref\netstandard1.3\System.ObjectModel.dll /reference:C:\Users\mareda\.nuget\packages\system.reflection.dispatchproxy\4.3.0\ref\netstandard1.3\System.Reflection.DispatchProxy.dll /reference:C:\Users\mareda\.nuget\packages\system.reflection\4.3.0\ref\netstandard1.5\System.Reflection.dll /reference:C:\Users\mareda\.nuget\packages\system.reflection.emit\4.3.0\ref\netstandard1.1\System.Reflection.Emit.dll /reference:C:\Users\mareda\.nuget\packages\system.reflection.emit.ilgeneration\4.3.0\ref\netstandard1.0\System.Reflection.Emit.ILGeneration.dll /reference:C:\Users\mareda\.nuget\packages\system.reflection.emit.lightweight\4.3.0\ref\netstandard1.0\System.Reflection.Emit.Lightweight.dll /reference:C:\Users\mareda\.nuget\packages\system.reflection.extensions\4.3.0\ref\netstandard1.0\System.Reflection.Extensions.dll /reference:C:\Users\mareda\.nuget\packages\system.reflection.metadata\1.4.1\lib\netstandard1.1\System.Reflection.Metadata.dll /reference:C:\Users\mareda\.nuget\packages\system.reflection.primitives\4.3.0\ref\netstandard1.0\System.Reflection.Primitives.dll /reference:C:\Users\mareda\.nuget\packages\system.reflection.typeextensions\4.3.0\ref\netstandard1.5\System.Reflection.TypeExtensions.dll /reference:C:\Users\mareda\.nuget\packages\system.resources.reader\4.3.0\lib\netstandard1.0\System.Resources.Reader.dll /reference:C:\Users\mareda\.nuget\packages\system.resources.resourcemanager\4.3.0\ref\netstandard1.0\System.Resources.ResourceManager.dll /reference:C:\Users\mareda\.nuget\packages\system.runtime.compilerservices.unsafe\4.3.0\lib\netstandard1.0\System.Runtime.CompilerServices.Unsafe.dll /reference:C:\Users\mareda\.nuget\packages\system.runtime\4.3.0\ref\netstandard1.5\System.Runtime.dll /reference:C:\Users\mareda\.nuget\packages\system.runtime.extensions\4.3.0\ref\netstandard1.5\System.Runtime.Extensions.dll /reference:C:\Users\mareda\.nuget\packages\system.runtime.handles\4.3.0\ref\netstandard1.3\System.Runtime.Handles.dll /reference:C:\Users\mareda\.nuget\packages\system.runtime.interopservices\4.3.0\ref\netcoreapp1.1\System.Runtime.InteropServices.dll /reference:C:\Users\mareda\.nuget\packages\system.runtime.interopservices.runtimeinformation\4.3.0\ref\netstandard1.1\System.Runtime.InteropServices.RuntimeInformation.dll /reference:C:\Users\mareda\.nuget\packages\system.runtime.loader\4.3.0\ref\netstandard1.5\System.Runtime.Loader.dll /reference:C:\Users\mareda\.nuget\packages\system.runtime.numerics\4.3.0\ref\netstandard1.1\System.Runtime.Numerics.dll /reference:C:\Users\mareda\.nuget\packages\system.runtime.serialization.formatters\4.3.0\ref\netstandard1.3\System.Runtime.Serialization.Formatters.dll /reference:C:\Users\mareda\.nuget\packages\system.runtime.serialization.primitives\4.3.0\ref\netstandard1.3\System.Runtime.Serialization.Primitives.dll /reference:C:\Users\mareda\.nuget\packages\system.security.claims\4.3.0\ref\netstandard1.3\System.Security.Claims.dll /reference:C:\Users\mareda\.nuget\packages\system.security.cryptography.algorithms\4.3.0\ref\netstandard1.6\System.Security.Cryptography.Algorithms.dll /reference:C:\Users\mareda\.nuget\packages\system.security.cryptography.encoding\4.3.0\ref\netstandard1.3\System.Security.Cryptography.Encoding.dll /reference:C:\Users\mareda\.nuget\packages\system.security.cryptography.primitives\4.3.0\ref\netstandard1.3\System.Security.Cryptography.Primitives.dll /reference:C:\Users\mareda\.nuget\packages\system.security.cryptography.x509certificates\4.3.0\ref\netstandard1.4\System.Security.Cryptography.X509Certificates.dll /reference:C:\Users\mareda\.nuget\packages\system.security.principal\4.3.0\ref\netstandard1.0\System.Security.Principal.dll /reference:C:\Users\mareda\.nuget\packages\system.security.principal.windows\4.3.0\ref\netstandard1.3\System.Security.Principal.Windows.dll /reference:C:\Users\mareda\.nuget\packages\system.text.encoding\4.3.0\ref\netstandard1.3\System.Text.Encoding.dll /reference:C:\Users\mareda\.nuget\packages\system.text.encoding.extensions\4.3.0\ref\netstandard1.3\System.Text.Encoding.Extensions.dll /reference:C:\Users\mareda\.nuget\packages\system.text.encodings.web\4.3.1\lib\netstandard1.0\System.Text.Encodings.Web.dll /reference:C:\Users\mareda\.nuget\packages\system.text.regularexpressions\4.3.0\ref\netcoreapp1.1\System.Text.RegularExpressions.dll /reference:C:\Users\mareda\.nuget\packages\system.threading\4.3.0\ref\netstandard1.3\System.Threading.dll /reference:C:\Users\mareda\.nuget\packages\system.threading.tasks.dataflow\4.7.0\lib\netstandard1.1\System.Threading.Tasks.Dataflow.dll /reference:C:\Users\mareda\.nuget\packages\system.threading.tasks\4.3.0\ref\netstandard1.3\System.Threading.Tasks.dll /reference:C:\Users\mareda\.nuget\packages\system.threading.tasks.extensions\4.3.0\lib\netstandard1.0\System.Threading.Tasks.Extensions.dll /reference:C:\Users\mareda\.nuget\packages\system.threading.tasks.parallel\4.3.0\ref\netstandard1.1\System.Threading.Tasks.Parallel.dll /reference:C:\Users\mareda\.nuget\packages\system.threading.thread\4.3.0\ref\netstandard1.3\System.Threading.Thread.dll /reference:C:\Users\mareda\.nuget\packages\system.threading.threadpool\4.3.0\ref\netstandard1.3\System.Threading.ThreadPool.dll /reference:C:\Users\mareda\.nuget\packages\system.threading.timer\4.3.0\ref\netstandard1.2\System.Threading.Timer.dll /reference:C:\Users\mareda\.nuget\packages\system.xml.readerwriter\4.3.0\ref\netstandard1.3\System.Xml.ReaderWriter.dll /reference:C:\Users\mareda\.nuget\packages\system.xml.xdocument\4.3.0\ref\netstandard1.3\System.Xml.XDocument.dll /reference:C:\Users\mareda\.nuget\packages\system.xml.xmldocument\4.3.0\ref\netstandard1.3\System.Xml.XmlDocument.dll /debug- /debug:portable /filealign:512 /nologo /optimize+ /out:obj\Release\netcoreapp1.1\project-name.dll /ruleset:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Team Tools\Static Analysis Tools\\Rule Sets\MinimumRecommendedRules.ruleset" /target:exe /warnaserror- /utf8output /deterministic+ /analyzer:C:\Users\mareda\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.Analyzers.dll /analyzer:C:\Users\mareda\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll AJAXRequest.cs DatapointSource.cs DatapointSourceODBC.cs DatapointValue.cs Program.cs SettingAccess.cs Startup.cs "C:\Users\mareda\AppData\Local\Temp\.NETCoreApp,Version=v1.1.AssemblyAttributes.cs" obj\Release\netcoreapp1.1\\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs obj\Release\netcoreapp1.1\\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs obj\Release\netcoreapp1.1\\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs obj\Release\netcoreapp1.1\project-name.AssemblyInfo.cs
project-name -> D:\ ... \project-name\bin\Release\netcoreapp1.1\project-name.dll
C:\Program Files\dotnet\sdk\1.1.0\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\PublishTargets\Microsoft.NET.Sdk.Publish.MSDeployPackage.targets(88,5): Error : Web deployment task failed. (Could not find file '\project-name.Parameters.xml'.)
Package failed.
2>Publish failed due to build errors. Check the error list for more details.
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Publish: 0 succeeded, 1 failed, 0 skipped ==========
example on command line that i use to exclude Admin path with -x
C:\Users\Test>C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe -v /Application.Web -p D:\Application.Web -x /Application.Web/Admin
after run this result is fine. But when i translate to csproj scripts.
from lib https://msdn.microsoft.com/en-us/library/ms164291.aspx
It does not parameter to exclude path from precompilation.
Currently command on csproj file
<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
<AspNetCompiler VirtualPath="Application.Web" PhysicalPath="$(WebProjectOutputDir)" />
</Target>
<Target Name="AfterBuild">
<RemoveDir Directories="$(BaseIntermediateOutputPath)" />
</Target>
You have to call the aspnet_compiler.exe directly as per this blogpost https://matthewrwilton.wordpress.com/2017/03/12/excluding-node_modules-folder-from-asp-net-compilation/
because the AspNetCompiler msbuild task doesn't have a property for exclusions.
Good thing is that you can call it with multiple exclusions, like so:
<PropertyGroup>
<exclusion1>some/path</exclusion1>
<exclusion2>another/path</exclusion2>
</PropertyGroup>
<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
<Exec Command="$(MSBuildFrameworkToolsPath)aspnet_compiler.exe -v temp -p $(WebProjectOutputDir) -x $(exclusion1) -x $(exclusion2)"/>
</Target>
Just remember to use the -x parameter once per exclusion.
this is my first post on stackoverflow. When I build my WPF, .NET40 project from VS 2013 (F6 key) application run fine, but when i use msbuild to automatic build and deploy my applications, then always i have crash on start.
My msbuid code:
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0" DefaultTargets="default">
<PropertyGroup>
<BaseDir>$(MSBuildProjectDirectory)</BaseDir>
<BinariesDir>$(MSBuildProjectDirectory)\mui\1.0\FirstFloor.ModernUI\Build\Binaries</BinariesDir>
<OutputDir>$(MSBuildProjectDirectory)\Setup\BuildResults\net4</OutputDir>
<Configuration Condition="'$(Configuration)'==''" >Release</Configuration>
<Platform Condition="'$(Platform)'==''">x86</Platform>
<PlatformTarget Condition="'$(PlatformTarget)'==''">x86</PlatformTarget>
<AllowUnsafeBlocks Condition="'$(AllowUnsafeBlocks)'==''">true</AllowUnsafeBlocks>
<TargetFrameworkVersion Condition="'$(TargetFrameworkVersion)'==''">v4.0</TargetFrameworkVersion>
<DefineConstants Condition="'$(DefineConstants)'==''">TRACE;NET4</DefineConstants>
<OutputPath Condition="'$(OutputPath)'==''">bin\AutoBuild\$(platform)\</OutputPath>
<MSBuildExtensions>$(BinariesDir)\MSBuild.Community.Tasks.dll</MSBuildExtensions>
<!--<SolutionFile>$(BaseDir)\Charon.sln</SolutionFile>-->
<SolutionFile>$(BaseDir)\cmu\cmu.csproj</SolutionFile>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildBinPath)\Microsoft.WinFX.targets" />
<UsingTask AssemblyFile="$(MSBuildExtensions)" TaskName="MSBuild.Community.Tasks.XmlUpdate" />
<UsingTask AssemblyFile="$(MSBuildExtensions)" TaskName="MSBuild.Community.Tasks.Zip" />
<Target Name="default" DependsOnTargets="Clean; Compile" />
<Target Name="Clean">
<!-- clear output dir -->
<RemoveDir Directories="$(OutputDir)" />
</Target>
<Target Name="Compile">
<MSBuild
Projects="$(SolutionFile)"
Targets="Clean;Build"
Properties="
Configuration=$(Configuration);
Platform=$(Platform);
PlatformTarget=$(PlatformTarget);
AllowUnsafeBlocks=$(AllowUnsafeBlocks);
TargetFrameworkVersion=$(TargetFrameworkVersion);
DefineConstants=$(DefineConstants);
OutputPath=$(OutputDir)"/>
</Target>
</Project>
and bat file, use to run msbuild:
#echo off
set msBuild=%WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild.exe
set innoSetup="%programfiles(x86)%\Inno Setup 5\iscc.exe"
rem Charon applications bulid version
set /a bulidVersion=(%date:~0,4%-2011)*12+%date:~5,2%
set appVersion=2.0.%bulidVersion%%date:~8,2%
rem MarcorpUpdater buid version AsmVersionMarcorpUpdater
set /a bulidVersion=(%date:~0,4%-2014)*12+%date:~5,2%
set marcorpUpdaterBuiltVersion = 1.0.%bulidVersion%%date:~8,2%
#echo on
rem call %msBuild% cmu\cmu.csproj /p:Configuration=Release;Platform=x86;AllowUnsafeBlocks=true;OutputPath=..\Setup\BuildResults\net45;PlatformTarget=x86;TargetFrameworkVersion=v4.5;DefineConstants="NET45;TRACE";AsmVersion="%appVersion%.*" /l:FileLogger,Microsoft.Build.Engine;logfile=cmu_Manual_MSBuild_LOG.net45.log /t:Rebuild
rem call %msBuild% charon\charon.cspro`enter code here`j /p:Configuration=Release;Platform=x86;AllowUnsafeBlocks=true;OutputPath=..\Setup\BuildResults\net45;PlatformTarget=x86;TargetFrameworkVersion=v4.5;DefineConstants="NET45;TRACE";AsmVersion="%appVersion%.*" /l:FileLogger,Microsoft.Build.Engine;logfile=charon_Manual_MSBuild_LOG.net45.log /t:Rebuild
rem call %msBuild% cmu\cmu.csproj /p:Configuration=Release;Platform=x86;AllowUnsafeBlocks=true;OutputPath=..\Setup\BuildResults\net4;PlatformTarget=x86;TargetFrameworkVersion=v4.0;DefineConstants="TRACE;NET4";AsmVersion="%appVersion%.*" /l:FileLogger,Microsoft.Build.Engine;logfile=cmu_Manual_MSBuild_LOG.net4.log /t:Rebuild
call %msBuild% build.msbuild /p:AsmVersion="%appVersion%.*" /l:FileLogger,Microsoft.Build.Engine;logfile=cmu_Manual_MSBuild_LOG.net4.log
pause
rem call %msBuild% charon\charon.csproj /p:Configuration=Release;Platform=x86;AllowUnsafeBlocks=true;OutputPath=..\Setup\BuildResults\net4;PlatformTarget=x86;TargetFrameworkVersion=v4.0;DefineConstants="NET4;TRACE";AsmVersion="%appVersion%.*" /l:FileLogger,Microsoft.Build.Engine;logfile=charon_Manual_MSBuild_LOG.net4.log /t:Rebuild
rem call %innoSetup% Setup\setup.iss "/dMyAppVersion=%appVersion%"
#echo off
set msBuild=
set innoSetup=
set appVersion=
set bulidVersion=
set marcorpUpdaterBuiltVersion=
Crash:
Application: net.marcorp.charon.modernui.exe
Framework version: v4.0.30319
Description: The process was terminated due to an unhandled exception..
Exception Info: System.Windows.Markup.XamlParseException
Stack:
at: System.Windows.Markup.WpfXamlLoader.Load(System.Xaml.XamlReader, System.Xaml.IXamlObjectWriterFactory, Boolean, System.Object, System.Xaml.XamlObjectWriterSettings, System.Uri)
at: System.Windows.Markup.WpfXamlLoader.LoadBaml(System.Xaml.XamlReader, Boolean, System.Object, System.Xaml.Permissions.XamlAccessLevel, System.Uri) at: System.Windows.Markup.XamlReader.LoadBaml(System.IO.Stream, System.Windows.Markup.ParserContext, System.Object, Boolean)
at: System.Windows.Application.LoadComponent(System.Object, System.Uri)
at: net.marcorp.charon.modernui.App.InitializeComponent()
at: net.marcorp.charon.modernui.App.Main()
I have an MSBuild file like this:
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<Param1>Hello world</Param1>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<Param1>Goodbye world</Param1>
</PropertyGroup>
</Project>
I am working on an external application and I need to be able to find out what the configured value of Param1 is. I need a way to correctly evaluate the MSBuild file so that any conditions are applied and then the correct parameter returned to the calling application.
Being able to do something like this would be great:
>MSBuild /p:Configuration=Release MyBuild.proj -extractParam:Param1
>Goodbye World
Any ideas? Is this possible with C# instead?
You can make the project output the value, then parse it using scripting/C#/....
Add this target to your project:
<Target Name="OutputParam1" AfterTargets="Build">
<Message Text="Param1 = $(Param1)"/>
</Target>
it will be invoked automatically after the Build target.
Then on the commandline:
>MSBuild /p:Configuration=Release MyBuild.proj /fl
where /fl cause the file msbuild.log to be generated, which will contain amongst others a line
Param1 = Goodbye world
because of the Message task. Now use e.g. powershell to output the matching part:
>powershell -command "$a = Select-String -Path msbuild.log -Pattern 'Param1 = (.+)'; $a.Matches[0].Groups[1].Value"
>Goodbye world
You can add a target which prints the param value:
<Target Name="ExtractParam1" >
<Message Text="$(Param1)" Importance="high" />
</Target>
The switches /v:m /nologo makes the output print just the value:
msbuild /p:Configuration=Release MyBuild.proj /t:ExtractParam1 /v:m /nologo