The target "_CopyBinDeployableAssemblies" does not exist in the project - visual-studio

I installed Visual Studio 2010 SP1 the other day and now when i try to "publish" my apps i get this error on ALL of my projects.
The target "_CopyBinDeployableAssemblies" does not exist in the project.
I have no idea what the problem is here and i find nothing on the all mighty Google and that makes me a bit nervous.
Can anyone point me in the right direction here or maybe somebody else has the same problem? Because it happens in all of my projects so i'm kind of amazed im alone with this problem.
The sites are ASP.NET Web Applications, some of them are mixed Web forms/MVC but one is only Webforms. 1 site is super mega simple with almost no references and i still get the error.

I also experienced this problem after installing Visual Studio 2010 SP1 Beta.
The missing target _CopyBinDeployableAssemblies is defined in:
$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets
I solved the problem by adding an <Import> element to the broken project files.
So if you have a depdendency on the above targets, which you can find out by looking for the following <Import> in your project files:
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets" />
You need to also import:
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />

From joao-angelo's blog post, add the following to the project file (.csproj/.vbproj)
<Target Name="Noop"></Target>
<PropertyGroup>
<CollectFilesFrom_binDeployableAssembliesDependsOn>
Noop
</CollectFilesFrom_binDeployableAssembliesDependsOn>
</PropertyGroup>
before importing
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets" />
That works for me using ClickOnce on VS2010 SP1 using App.config transform

Hoho, Jacob is right!
When we install VS 2010 SP1 the default MSBuild path will focus to folder
[C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0]
not
[C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0] any more.
And the [Microsoft.WebApplication.targets] file has a build target named [_CopyBinDeployableAssemblies].
So we just add a [_CopyBinDeployableAssemblies] target to our project file(can open it with Notepad :))
, the problem was solved
Ex: <Target Name="_CopyBinDeployableAssemblies"></Target>. Just need an empty target :)

The answer given above by Ragge was what I needed. But in my case, I only added the second line. The first line Ragge gave was already in the project file.
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />

It's VS 2013 SP 3 and I'm still having this issue!
In order to fix it I had to change the following line in the failing to build projects from:
<Import Project="$(VSToolsPath)\Web\Microsoft.Web.Publishing.targets" Condition="'$(VSToolsPath)' != ''" />
to the following line:
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />

Well, spent 4h on this today and i solved it now. But unfortunately i do not have a definite answer what the problem was. Buit i will describe what i did.
Uninstalled SP 1 and got a couple errors. These where because i didn't have the VS install media and it where asking for it.
SP1 seemed to have been removed but i still got the error.
Downloaded VS Ultimate Trial and tried to do a repair, didn't help.
Downloaded VS 2010 SP1 again and installed it. Still the same problem.
Uninstalled VS SP1 with access to VS Ultimate install media and i only got one error where it needed some VS Express stuff, i pressed cancel on that one and it said the uninstall failed.
Launched Visual Studio and the problem where gone! Hallelujah!
And well, i don't blame MS for this at all. I knew it where a beta but i never had issues like this before.
Hope this solves the problem for somebody else.

The answer Ragge gave worked for us as well. I had a solution I hadn't opened since SP1 install that just refused to build with the same error. Edited the project file in Notepad to include those two statements and viola! issue solved. Thanks so much for your diligence!
Addition: A colleague mentioned that the addition of the import will cause builds happening outside of Visual Studio to likely complain (Command line msbuild, build server) because Microsoft.WebApplication.targets doesn't exist there. So we changed the import line to read:
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="$(BuildingInsideVisualStudio) == true AND exists('$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets')" />
These conditions were important for our builds as we do all deploys using the build server and msdeploy.

Undeploy the project and edit and add following code in project file at end of <Import>
<Target Name="_CopyBinDeployableAssemblies"
Condition="Exists('$(MSBuildProjectDirectory)\_bin_deployableAssemblies')">
<CreateItem Include="$(MSBuildProjectDirectory)\_bin_deployableAssemblies\**\*.*"
Condition="Exists('$(MSBuildProjectDirectory)\_bin_deployableAssemblies')"
Exclude="$(MSBuildProjectDirectory)\_bin_deployableAssemblies\.svn\**\*">
<Output ItemName="_binDeployableAssemblies" TaskParameter="Include" />
</CreateItem>
<Copy SourceFiles="#(_binDeployableAssemblies)"
DestinationFolder="$(OutDir)\%(RecursiveDir)" SkipUnchangedFiles="true"
Retries="$(CopyRetryCount)"
RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)" />
</Target>

Related

Visual Studio New project wont run tests

Visual Studio 2019 is not detecting or discovering NUNit nor MSTest unit tests at all. I installed it fresh just a week ago. The MS guide here https://learn.microsoft.com/en-us/visualstudio/test/getting-started-with-unit-testing?view=vs-2019&tabs=mstest does not work.
A few threads hold possible solutions, but none that I've tried helped have helped. I'm new to C# so much of the steps have taken a long time to figure out, but while my application is progressing nicely I really want to work and learn in a TDD style.
Even if a create a new blank MSTest project, with no application code or libs in the solution at all, the example/template project does not work, so I'm missing something big someplace. (I have .NET Core SDKs installed - my intent is to target macOS and linux at a future point.)
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="nunit" Version="3.13.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
</ItemGroup>
</Project>
Threads I have tried: Tests not running in Test Explorer Why will Visual Studio 2019 will not run my unit tests? Visual Studio 2019 Test Explorer puts all tests under "Not Run Tests"
If I create a project targeting .NET 4.7 all is good, it's when I want to target Core that I'm unstuck, if that helps.
Stuck again
I had to install a component called "NUnit 3", https://marketplace.visualstudio.com/items?itemName=NUnitDevelopers.NUnitTemplatesforVisualStudio worked for a moment... but when I added a testcase, it all broke again.
Did the nuget package updates, still not working.
I cloned. from git this project https://github.com/dotnet/samples/tree/master/core/getting-started/unit-testing-using-nunit
And it does not work either.
I then re-installed 2019, and emailed my project to a friend, who merely removed the nunit nuget modules, added them back and then it worked for him, but the project he sent me back did not work. Module versions unchanged
I opened the same project in the Microsoft developer VM/iso image and the project works just fine. so it's my environment that is incompatible with nunit somehow. Is there a way to see some traces?
Changed the installation drive from D: to C: I get this error now
Testhost process exited with error: A fatal error occurred, the required library hostfxr.dll could not be found.
If this is a self-contained application, that library should exist in [C:\Users\zapho\src\c#\tutorials\working\ConsoleApp1\ConsoleApp1\NUnit.Tests2\bin\Debug\netcoreapp3.1\].
If this is a framework-dependent application, install the runtime in the default location [C:\Program Files\dotnet] or use the DOTNET_ROOT environment variable to specify the runtime location.
. Please check the diagnostic logs for more information.
Testhost process exited with error: A fatal error occurred, the required library hostfxr.dll could not be found.
If this is a self-contained application, that library should exist in [C:\Users\zapho\src\c#\tutorials\working\ConsoleApp1\ConsoleApp1\NUnit.Tests2\bin\Debug\netcoreapp3.1\].
If this is a framework-dependent application, install the runtime in the default location [C:\Program Files\dotnet] or use the DOTNET_ROOT environment variable to specify the runtime location.
. Please check the diagnostic logs for more information.
You need to add the Microsoft.NET.Test.Sdk NuGet package to your solution to run tests in Visual Studio.
Modify your project file,
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="nunit" Version="3.13.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
</ItemGroup>
</Project>
Fixed it by eventually setting environment variable
DOTNET_ROOT=D:\Program Files\dotnet\
as per an answer
https://stackoverflow.com/a/61453119/337598

How to build VS 2015 solution with projects which import targets and props from nuget packages using msbuild 14?

The scenario
You add a nuget package, which in turn injects <Import .../> statement into your csproj file which references a targets or props file from the package itself.
This works fine when building the code in Visual Studio, but fails miserably when building the same solution with msbuild.
The root cause
There are several. First, the logic to restore the packages is executed by the VS itself outside of the build proper. We can solve it by importing Nuget.targets which would run the RestorePackage target before the build. Check.
But the second problem is more serious. The Import statements importing targets/props from the packages can only be resolved after the packages are restored. Meaning restoring the packages cannot be part of the build. It must happen before the msbuild is given the solution to build. Yes, Visual Studio does it already, but I do not use Visual Studio on my Gated Check-In or CI server. I need it to work with msbuild.
What one can do?
As far as I understand, I need to be able to run the same logic VS does only on the command line. I.e. identify the packages and restore them before running msbuild. But devil is in details. Cannot be I am the first one to face this problem.
How do you do it?
Found the answer in this blog post - http://sedodream.com/2013/06/06/HowToSimplifyShippingBuildUpdatesInANuGetPackage.aspx
Following this blog I have created before.MySolutionName.sln.targets file with the following content:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Restore">
<Target Name="Restore" BeforeTargets="Build">
<Exec Command=".nuget\nuget.exe restore $(MSBuildProjectName)" LogStandardErrorAsError="true" />
</Target>
</Project>
Now all the packages in the solution are restored before the build.
Thank you, Sayed Ibrahim Hashimi.

Error NU1105 Unable to find project information - The project file may be invalid or missing targets required for restore

All of a sudden, I am getting the following errors for 3 projects in a solution:
Error NU1105 Unable to find project information for 'C:\code\example\src\libs\example.I18n\example.I18n.csproj'.
The project file may be invalid or missing targets required for restore.
The only thing that has changed in the project is a couple of DB changes, but I never had any issues in the past. The only other thing is that I updated to Visual Studio 2017 15.5. Could that cause issues?
I have tried removing and recloning the solution from source control, but still getting errors. No problems on my colleagues' machines, so it must be something local.
Example of one of the .csproj files if this helps:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net452</TargetFramework>
<AssemblyName>Example.I18n</AssemblyName>
<PackageId>Example.I18n</PackageId>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.1" />
<PackageReference Include="MessageFormat" Version="1.0.1" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
</Project>
I also got the same after upgrading to version 15.6 of Visual Studio 2017.
Closing VS and deleting the .vs folder fixed it for me.
For me, the casing of the project file on disk did not match the casing in the solution file.
Say I had a solution with LibraryA.csproj and LibraryB.csproj, where LibraryB.csproj has a reference to LibraryA.csproj. Having an incorrect casing for LibraryA.csproj in the solution file would cause NU1105 when building LibraryB.csproj:
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibraryA", "LibraryA\Librarya.csproj", "{24DEBB3B-762A-491D-8B83-6D078C0B30C0}"
I started seeing this problem after upgrading to version 15.5 of Visual Studio 2017. I did not encounter this problem with version 15.4.5.
I had this problem and I just followed what the error message recommends inside VS:
to restore the solution.
So I opened a command line or package manager console, chdir into the directory with the solution (.sln) file and just issued
C:> dotnet restore .\mySolution.sln
Problem was fixed.
This error message will also occur if a referenced project is not included in the solution. I encountered this problem today, and I found the fix here.
I encountered this error when having a duplicate reference to a project.
<ProjectReference Include="..\ProjectA.csproj" />
<ProjectReference Include="..\ProjectA.csproj" />
Removing the duplicate reference resolved the error.
What worked for me was to
Remove the offending project
Build the solution
Re-add the project.
Seems that some projects were removed from solution file (don't know why). Fixed by undoing these solution file changes
I have next project structure (.Net Core projects):
../classLib
../../../webProject1
../../../webProject2
../../myWebProjects.sln
webProject1 and webProject2 reference classLib as project itself (not as .dll). When I opened my solution in VS 2019 and tried to build I got identical error NU1105: Unable to find project information for '../classLib.csproj'. error.
Before build depended projects you need to restore there dependency. What I did, just add
next Target to my webProject1.csproj and webProject2.csprojfiles.
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="dotnet restore" />
</Target>
Open powershell and running restore command solved my issue.
dotnet restore Sample.sln
I correct this error by simply running the clean solution option.
Right click the solution in the solution explorer and choose clean solution.
This is insane, i tried all this:
updated VS. manually deleted all bin folders, run dotnet restore, clean rebuild nothing works
solution: finally i unload all the projects and start reloading them into solution, one by one in the order they show dependency errors. then the last one just cascade fixes everything. No idea what was wrong
I recently came across Error NU1105 while using JetBrains Rider on Linux. So this involves Mono and the MSBuild version that comes with it.
It turns out this was being caused by my solution files being in a directory that was a symbolic link to another directory. I believe MSBuild was dereferencing the linked directory and instead referencing the source directory. This makes some of the referenced paths completely different, even though they are the exact same files, case, everything else. Opening the solution from the original location works perfectly now for me.
Reload the project which causes the problem, this will fix the issue,
As mentioned in the following link :
https://learn.microsoft.com/en-us/nuget/reference/errors-and-warnings/nu1105
This happend to me when I had files with names exceeding OS's max path limit. Check your names ;)
In my case I did it and it worked for me
goto Tools/CommandLine/Developer Command Prompt or Developer Powershell
type this command and Enter "dotnet restore".
Build your solution
That's all
Just use: "dotnet restore MySolution.sln",
Where MySolution.sln is your solution.
I was getting this error error NU1105: Unable to find project information for 'C:\folder2\project1.csproj'.
but project1 that I had as part of the solution was located in C:\folder1\project1.csproj (it was also there in c:\folder2\project1.csproj too but not part of the solution, so it was confusing)
Once I changed the reference to the correct location of the project it worked.
After spending 3 hours, trying out numerous solutions, what worked for me is that I had to undo my root solution sln file...some of the project references were removed..not sure how.

TransformXml task could not be loaded from Microsoft.Web.Publishing.Tasks.dll

Has anyone seen this error and know how to fix it?
The "TransformXml" task could not be loaded from the assembly C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Web\Microsoft.Web.Publishing.Tasks.dll.
Could not load file or assembly 'file:///C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Web\Microsoft.Web.Publishing.Tasks.dll' or one of its dependencies. The system cannot find the file specified.
Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.
I read elsewhere that the problem is when you don't have SQL Server installed. But I do have SQL Express 2012 x64 installed with SP1. I am also running VS 2013 Professional.
I have ran this exact same solution in VS 2012 express with no problems.
The answers provided by Dai Bok and emalamisura work fine as long as you use Visual Studio 2012.
For VS 2013 this fails as well. In order to make this work with all versions of Visual Studio you should:
Open the project file (.csproj) of the project failing to load
Search for <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets" />
Change it to <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Web\Microsoft.Web.Publishing.targets" />
Reload the project
That will set the correct version of Visual Studio dynamically and properly.
To get mine to work, I just copied my v10.0 folder and renamed it to v11.0, and things seems to work well from then on. That's the quick fix for now.
As this is probably not the best solution, and although it works, I was going to try installing the Microsoft Windows SDK for Windows 7 and .NET Framework 4 Windows SDK for Windows 7 and .NET Framework 4, but it is taking to long to download.
To fix the issue,
Find the Visual studio Installer in your computer
Click or tap to start the installer, and then select Modify.
From the Individual Components screen, select Asp.net and web development tools and then select Modify/Install.
This solved the issue as it creates the dll's in the mentioned path.
I've been combating this problem on our build server for several days, so I figured I'd document the resolution I came to. First, my build server has the web publishing extensions installed. I can use the TransformXml task to my heart's content inside of a web application project.
To use it outside of a web application project, I tried to add the UsingTask element to my project and point it to the right place using ms build properties (as Benjamin demonstrated). However, they weren't there on my build server (those with easy access to the file system of their build server can probably skip this and just install the relevant package to Visual Studio). I even went so far as to hard code visual studio versions, but it always dropped that error on me.
I finally gave up, pulled the DLLs from my local PC:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.Publishing.Tasks.dll
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.XmlTransform.dll
I uploaded them to source control and added that folder to my build's workspace (Edit Build Definition -> Source Settings -> Source Control Folder). From there, I don't even need to reference the folder -- here's what my UsingTask looks like:
<UsingTask TaskName="TransformXml" AssemblyFile="Microsoft.Web.Publishing.Tasks.dll" />
Now I can use the TransformXml task to my heart's content from any project.
For VS2019
<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(MSBuildToolsVersion
I replaced MSBuildToolsVersion with VisualStudioVersion.
Because there are only v12.0, v14.0 and v15.0 in my VisualStudio folder, I edit my project file and change the reference path from v10.0 to v14.0. Then the project builds successfully.
Before:
<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
After:
<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
Solutions provided seem to work for using VS as an IDE, but if you use DotnetCore via CLI or on a unix based system this does not work.
I found that the following seem to work
<PropertyGroup>
<XmlTransformDllPath Condition="'$(XmlTransformDllPath)' == '' AND '$(MSBuildRuntimeType)' == 'core'">$(MSBuildSDKsPath)/Microsoft.NET.Sdk.Publish/tools/net5.0/Microsoft.NET.Sdk.Publish.Tasks.dll</XmlTransformDllPath>
<XmlTransformDllPath Condition="'$(XmlTransformDllPath)' == '' AND '$(MSBuildRuntimeType)' != 'core'">$(MSBuildSDKsPath)/Microsoft.NET.Sdk.Publish/tools/net472/Microsoft.NET.Sdk.Publish.Tasks.dll</XmlTransformDllPath>
<XmlTransformDllPath Condition="!Exists($(XmlTransformDllPath))">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Web\Microsoft.Web.Publishing.Tasks.dll</XmlTransformDllPath>
</PropertyGroup>
<UsingTask TaskName="TransformXml" AssemblyFile="$(XmlTransformDllPath)" />
This solution takes into account netcore, full .net
For some reason MSBuildSDKsPath and MSBuildExtensionsPath32 are different on windows when using CLI vs VS2019
CLI:
MSBuildSDKsPath = C:\Program Files\dotnet\sdk\5.0.103\Sdks
MSBuildExtensionsPath32 = C:\Program Files\dotnet\sdk\5.0.103
Vs2019
MSBuildSDKsPath = C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Sdks
MSBuildExtensionsPath32 = C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild
Which on my Mac returns /usr/local/share/dotnet/sdk/5.0.201
Only problem I see is with the tools/net5.0 part of the name which changes ever release
Also created https://github.com/dotnet/sdk/issues/16469 and answers this on The "TransformXml" task was not found (error MSB4036) on TeamCity build
The correct answer to this is to unload the project in question and then edit the csproj file, look for an entry where they are referencing the 10.0 path and change it to point to 11.0 instead.
You need two things to make it work:
1) Install Visual Studio Build Tools (You don't need the whole Visual Studio, only the VS Build Tools) with selected "Web development build tools" option on your build server
https://www.visualstudio.com/pl/thank-you-downloading-visual-studio/?sku=BuildTools&rel=15
2) Ensure that path to Microsoft.Web.Publishing.Tasks.dll is correct
<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(MSBuildToolsVersion)\Web\Microsoft.Web.Publishing.Tasks.dll" />
For me it started working just by adding reference to the NuGet package MSBuild.Microsoft.VisualStudio.Web.targets v14.0.0.3
Even no need to add UsingTask element to the project file as it mentioned by the package author
https://github.com/pdonald/nuget-webtargets
Just install the NuGet package. The package automatically sets the
$(VSToolsPath) property to use the targets file in the tools folder.
And then I was able to use TransformXml and other tasks, defined in the package, for instance to transform app.config
<Target Name="app_config_AfterCompile" AfterTargets="AfterCompile" Condition="Exists('app.$(Configuration).config')">
<!--Generate transformed app config in the intermediate directory-->
<TransformXml Source="app.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="app.$(Configuration).config" />
<!--Force build process to use the transformed configuration file from now on.-->
<ItemGroup>
<AppConfigWithTargetPath Remove="App.config" />
<AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
<TargetPath>$(TargetFileName).config</TargetPath>
</AppConfigWithTargetPath>
</ItemGroup>
</Target>
Just in case someone is using an SDK-style csproj, you can achieve this without having to install Visual Studio on the build server.
First you should install the SlowCheetah nuget package to your project. Once you install it, you'll see the following in your SDK-style project.
<PackageReference Include="Microsoft.VisualStudio.SlowCheetah" Version="3.2.20">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Then make sure you add the GeneratePathProperty="true" attribute (see below). This is very important for the next part because it'll help you grab the path of where the nuget package is restored on your machine. George Dangl explains it in his article here.
<PackageReference Include="Microsoft.VisualStudio.SlowCheetah" Version="3.2.20" GeneratePathProperty="true">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Import the SlowCheetah targets into your project:
<Import Project="$(PkgMicrosoft_VisualStudio_SlowCheetah)\build\Microsoft.VisualStudio.SlowCheetah.targets" />
You can now use an target command (in this case after publish) to apply some custom transformations. If you need to, you can always hard-code the file names below instead of using the variables in the below example.
<Target Name="AfterPublishs" AfterTargets="Publish">
<TransformTask Source="Web.config" Transform="Web.$(Configuration).MyCustomTransformFile.config" Destination="$(PublishDir)\Web.config" />
</Target>
If you haven't used SlowCheetah before, I recommend checking it out. They have a Visual Studio extension that will make it easier for you to preview transform files.

MSBuild target PipelinePreDeployCopyAllFilesToOneFolder cannot be found when deploying

Deploying a Web Application Project from VS2010 RTM causes an error in MSBuild. It complains that the PipelinePreDeployCopyAllFilesToOneFolder target cannot be found.
Is there any way to further diagnose this?
Thank you.
I had the same problem and when I looked in the .csproj file for my web application I had the following lines...
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="'$(Solutions.VSVersion)' == '8.0'" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" Condition="'$(Solutions.VSVersion)' == '9.0'" />
I guess this happened since I had recently upgraded from VS2008 to VS2010. So it looks like the during the conversion process it got all screwed up. To fix it I just replaced those lines with ...
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
After that everything worked as it should.
I've seen the answer given by brodie in several places online, which is strange to me because this task (PipelinePreDeployCopyAllFilesToOneFolder) is not even contained in this target (Microsoft.WebApplication.targets):
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
If you actually go and find this file (on an x64 machine it's in C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets, or the version 12.0 equivalent if you're using VS2013) and open it in a text viewer, you'll see it's not there..
It's actually contained in the file that Sayed Ibrahim Hashimi mentions, which is the Microsoft.Web.Publishing.targets file (C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets).
So to get this into your MSBuild/.csproj file, include the following:
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets" />
Do you have Visual Studio 2010 installed on the machine where you are trying to build? If so then look for a file located at %Program Files(x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets it should have that target. If it doesn't then those files may have been corrupted and probably reparing your VS 2010 install should fix it.
I think the Web Deployment targets/tasks are shipped with VS itself and not the .NET framework, so you need VS installed (or you can manually configure the machine)/
Even though this is an old post It still provided some great help!
My setup is using a remote host for Automation of a project built in VS2013.
The remote host doesn't contain all the VS2013 targets when you solely install MSBuild 12.0 and this resulted in the 'Microsoft.Web.Publishing.targets' file not existing.
To get around this target error I had to copy the files from my local VS2013 path and copy this to the remote host in the equivalent location.

Resources