When I publish my solution that contains an ASP.NET Web Application for the first time the .wpp.targets file is ignored. The publish folder contains also the files that shouldn't be published.
After removing all the files in my publish folder and publish again everything is fine. But when I do a clean solution from visual studio the .wpp.targets file is ignored again.
Hopefully someone can solve this problem or explain why this happens. I would like to use it on our build server where the build always starts with a clean solution.
What I have used:
MSBuild version 15.8.166 "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\msbuild.exe" WebApplication1.sln /p:DeployOnBuild=true /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:publishUrl=C:\test
MSBuild version 16.0.360 "C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin\msbuild.exe" WebApplication1.sln /p:DeployOnBuild=true /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:publishUrl=C:\test
I ran the builds with a wpp.target file which contained the name of my project, but I tried it also with the following MSBuild parameter: /p:WebPublishPipelineCustomizeTargetFile=C:\Users\username\source\repos\Test\WebApplication1\test.wpp.targets
Update
When building a project for the first time or after the build is cleaned the wildcards in the *.wpp.targets file dont work. Here is an example of my *.wwp.targets file:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ExcludeFromPackageFolders Include="bin\roslyn">
<FromTarget>Roslyn</FromTarget>
</ExcludeFromPackageFolders>
<ExcludeFromPackageFiles Include="bin\Newtonsoft.*">
<FromTarget>Newtonsoft</FromTarget>
</ExcludeFromPackageFiles>
</ItemGroup>
</Project>
Roslyn is excluded as expected. But Newtonsoft.* are not excluded, because there is a wildcard in the name.
When the obj folder is manual deleted or the build is executed before than the wildcards work as well.
What I have used: MSBuild version 15.8.166 & MSBuild version 16.0.360
Example of an used msbuild comando: "C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin\msbuild.exe" WebApplicationTestForMsBuild.sln /p:DeployOnBuild=true /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:publishUrl=C:\test
In other projects we have noticed that some wildcard seem to work for the most files but not for all of them. An example of this is: "<ExcludeFromPackageFiles Include="bin\*.pdb">
" the most pdb files or exclude but not all of them.
I would like to use it on our build server where the build always starts with a clean solution. This problem seems to be a bug in msbuild, but if you know a solution please share it with me.
Update 2
The steps of one of the tests that I performed:
- Create an new Empty ASP.Net Web Application (.NET Framework 4.6.1) project in Visual studio Enterprise 2017 (version 15.9.7).
- Add the [ProjectName] .wpp.targets to the project which contains the earlier described data.
- Install the nuget package Newtonsoft.Json (version 12.0.1) (Used as an example)
- I run the following command at the command prompt: "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\msbuild.exe" [projectName].csproj /p:DeployOnBuild=true /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:publishUrl=C:\test /p:DeleteExistingFiles=True
- I looked into the C:\test\bin folder and I found the following files:
- Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll
- Newtonsoft.Json.dll
- Newtonsoft.Json.pdb
- [projectName].dll
- [projectName].pdb But the Newtonsoft.Json.dll and the Newtonsoft.Json.pdb files should not be published.
- I run the msbuild command again and it works as expected. I only got the following files in the publish folder:
- Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll
- [projectName].dll
- [projectName].pdb
- I did a clean solution in my visual studio instance or by the msbuild command: "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\msbuild.exe" WebApplication7wpp.csproj -target:Clean
- Run the msbuild build command again and the Newtonsoft files are added again.
The wpp.targets works as expected when I don't use the wildcards.