Payload contains two or more files with the same destination path - visual-studio

I created a new UWP MSTest Project and I added a reference to my main application. When I build the solution, get the an error:
Payload contains two or more files with the same destination path
Along with the conflicting files. I checked the copy to local for the files and they are set to Do not copy. Here's a sample of the error messages:
Severity Code Description Project File Line Suppression State
Error Payload contains two or more files with the same destination
path 'Assets\Square44x44Logo.targetsize-24_altform-unplated.png'.
Source files:
C:\Users\joe.nuget\packages\newtonsoft.json\11.0.1-beta1\lib\netstandard2.0\Newtonsoft.Json.dll
C:\Program Files (x86)\Microsoft SDKs\Windows
Kits\10\ExtensionSDKs\TestPlatform.Universal\15.5\Redist\CommonConfiguration\neutral\Newtonsoft.Json.dll App.Test C:\Program
Files (x86)\Microsoft Visual
Studio\2017\Community\MSBuild\Microsoft\VisualStudio\v15.0\AppxPackage\Microsoft.AppXPackage.Targets 1747
Error Payload contains two or more files with the same destination
path 'Assets\Wide310x150Logo.scale-200.png'. Source files:
E:\App.Test\Assets\Wide310x150Logo.scale-200.png
E:\App\Assets\Wide310x150Logo.scale-200.png App.Test C:\Program Files
(x86)\Microsoft Visual
Studio\2017\Community\MSBuild\Microsoft\VisualStudio\v15.0\AppxPackage\Microsoft.AppXPackage.Targets 1747

This happens when the content file names are the same for the app itself and the test project. Even though you set them to Do not copy, they are still conflicting during the intermediate step of building the test project.
The simplest solution is to rename or delete the Asset PNGs inside the Test Project so that they do not conflict with your app itself.
Newtonsoft.Json
Problem with Newtonsoft.Json is a known issue that has been reported to the Visual Studio team and the fix is now pending release.
The only workaround mentioned is the following by Morten Nielsen:
As a workaround and if you can live with the v9 version the test
project ships with, you can add a direct assembly reference to the
Json.net lib that they use, instead of using the nuget reference.

Related

Different results with MsBuild and Visual Studio

I have a solution, which consists out of 2 projects: regular class library for .NET 4.5 + website (not web application) project.
When I build this solution with Visual Studio - all referenced assemblies from Nuget packages and local references are copied to bin folder of website project.
If I try to build solution with MsBuild - bin folder of website project does not receive any assemblies.
Website project is not selected to be built in VS configuration (which is reported by message in both cases)
Edit - here is additional explanation.
When I clone a project from git - bin folder of website contains only 4 assemblies already checked in:
If I will run msbuild command with /t:Build or /t:Rebuild and /p:Configuration=Release;Platform="Any CPU" - I'll receive just an output of postbuild event in my other project, included in solution:
However, if I execute build from VS (Ctrl + Shift + b) in Release/Debug config - bin have all required assemblies for running web application.
Edit 2: Link to example solution - https://github.com/akuryan/csharp-website-test
When one builds it with msbuild TestApp.sln /t:Rebuild /p:Configuration=Release;Platform="Any CPU" - this results in only Test.Core.* and LetsEncrypt.Umbraco.dll (initially checked in) found at ~\Test.Web\bin\ (where Test.Web is website project). If one builds TestApp.sln with VisualStudion 2015 (I suppose, 2013 and 2017 will be the same) - ~\Test.Web\bin\ gets whole amount of assemblies.
Different results with MsBuild and Visual Studio
That because the all dll.refresh file in bin folder alongside the binary file are ignored by .gitignore.
Since Web Site projects do not have any project file (.csproj) to put the assembly references, the *.dll.refresh files are used by MSBuild to understand the assembly references. The contents of the file is the relative path to the .dll via the packages folder for the solution. When you ignore all those .dll.refresh by .gitignore, MSBuild could not understand how to handle the dll files.
To test this, I created a website project, add a nuget package to it, then delete the dll files but keep the .dll.refresh files in the bin folder. Build the website project by MSBuild command line:
msbuild.exe TestWebsite.sln /t:Rebuild
After this command complete, the dll files are copy to the bin folder.
So build and package restore to work it looks like you need to keep the .dll.refresh files in the bin folder. You can remove the other binaries from your version control system.
Note: If you want to get those .dll.refresh back, you can use the command line in the Package Manager Console:
update-package -reinstall
Hope this helps.

Why am I getting access denied to these files?

Suddenly I cannot rebuild my project in VS 2017. I get these messages:
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(4222,5): error MSB3021: Unable to copy file "C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\4.4.1.0\FSharp.Core.dll" to "bin\Debug\FSharp.Core.dll". Access to the path 'bin\Debug\FSharp.Core.dll' is denied.
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(4222,5): error MSB3021: Unable to copy file "H:\Dropbox\BitBucket\VSProjects\Fractal10\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll" to "bin\Debug\Newtonsoft.Json.dll". Access to the path 'bin\Debug\Newtonsoft.Json.dll' is denied.
Any suggestions on how to solve this problem?
Possible causes:
The app you are trying to build/debug can be running or stuck open
Tests locking the assemblies could be using them
post-build steps listed in the properties page of a project could be using them
while building multiple projects in parallel: another project could have decided to use those dll in the output folder for those references
Visual Studio's F# interactive if set to not shadow copy assemblies could cause it.
anything else that causes a file to be locked in windows
It happened today for me, I had pulled a branch from git repo and the project was not getting compiled or cleaned.
I had to uncheck read-only option for the root directory and the nested files & folders of the root directory.
Go to the folder where the project is, right click on the directory, click properties, Uncheck Read-only option.

Why does Visual Studio publish packages.config too?

When I use the option Publish... selecting as target the file system in Visual Studio 2015 it compiles the code, do the XML transformation in the Web.config files and copy the files to the folder I specified.
It does not copy any *.cs file as expected since it is compiled.
Something that I don't understand is why it publishes the Nuget Config file (packages.config), after all, the files needed are already in the bin folder.
I found this question that says how to avoid but not the reason they decided this file would be usable on the server.
Can I stop VS from publishing packages.config?
Anyone know why packages.config end up in the publish folder?

devenv copies files from other project during incremental build

I have 3 projects; Project1.Web, Project1.Service and Project1.Common.
Both Project1.Web and Project1.Service have dependencies on Project1.Common.
If I rebuild the solution which contains all 3 projects; all works correctly.
If I change a file in Project1.Web; files are built to Project1.Web\bin - all works correctly.
If if change a file in Project1.Service files are built to Project1.Service\bin\Debug AND some are copied to Project1.Web\bin. The copied file is Project1.Common.dll, but Project1.Web.dll is not built (or copied).
The file modified in Project1.Service is not shared, its just modified to trigger an incremental build of Project1.Service.
Does anyone know why Visual Studio would be copying a build artifact to a a directory that is not part of the incremental build?
Currently this sequence of events leaves Project1.Web is a non-working state as Project1.Service and Project1.Web have dependencies on different versions of the same assembly via a third party assembly. If we decide to make a change to Project1.Service then it has the side-effect of breaking Project1.Web.
I've tried/checked the following:
There are no dependencies between Project1.Web and Project1.Service (either direction).
The file modified in Project1.Service is not shared; and there are no pre/post build events defined.
Executing msbuild on the Project1.Service.csproj project file does not have the same effect.
Denying write/create permission on the bin directory under Project1.Web does not cause the incremental build to fail.
No output is emitted in the detailed or diagnostic msbuild output that references Project1.Web (from within Visual Studio)
Using procmon, I can see that devenv is using mswebprj.dll (C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Packages\mswebprj.dll) - which invokes the copy of the file.

*.sln will build in Xamarin Studio but not in xbuild

I have a Visual Studio solution that contains 16 C# projects. I also have a separate build.proj file which contains three <Target>s:
Build, which contains an <MSBuild> reference to the *.sln
Package, which contains the <MakeDir> and <CopyCommands> to copy the built DLL/EXE files along with various data files to a $(StagePath) directory.
Deploy, that copies files from the stage path to a deploy path.
I was able to run the command xbuild /t:Deploy build.proj to build the *.sln and copy its files to the appropriate location, until recently when IT decided to move my Documents folder onto a network drive.
Now, whenever I try to run this xbuild command, I get several errors like the one below. (The reference is to one of the dependencies within the same solution.)
error CS0234: The type or namespace name `Util' does not exist in the namespace `Contoso'. Are you missing an assembly reference?
But whenever I do a “Build All” on the same *.sln from Xamarin Studio, I get a successful build with 0 errors and 0 warnings. So why can't xbuild find these assembly references if Xamarin Studio can?

Resources