What can I do about my build error in Visual Studio 2019 .net core? cannot find part of path \obj\Debug\net48\Package\PackageTmp - msbuild

I am so confused, this is my error:
1>obj\Debug\net48\Package\PackageTmp.
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VisualStudio\v16.0\Web\Microsoft.Web.Publishing.targets(3000,5): error : Copying file obj\Debug\net48\NuGet\DD3A9BE7C0EDA549CD5B7B690E0621F0E2C932EC\Glass.Mapper.Sc.100\5.8.173\App_Config/Include/Glass/Glass.Mapper.Sc.Start.config to obj\Debug\net48\Package\PackageTmp\obj\Debug\net48\NuGet\DD3A9BE7C0EDA549CD5B7B690E0621F0E2C932EC\Glass.Mapper.Sc.100\5.8.173\App_Config/Include/Glass/Glass.Mapper.Sc.Start.config failed. Could not find a part of the path 'obj\Debug\net48\Package\PackageTmp\obj\Debug\net48\NuGet\DD3A9BE7C0EDA549CD5B7B690E0621F0E2C932EC\Glass.Mapper.Sc.100\5.8.173\App_Config/Include/Glass/Glass.Mapper.Sc.Start.config'.
1>Done building project "some.project.ORM.csproj" -- FAILED.
I have tried to delete the obj\Debug folder in the file system as well as the solution, as some have suggested. I have unloaded the project to review the .csproj file, I didn't see anything strange. I tried removing the Nuget Package and Reinstalling it. I just am not certain.
any help would be welcomed.
Note: I checked the directories do exist and they do. I even deleted the /obj/Debug folders from the solution as well as the source, as suggested, nothing seems to be working.
here is the .csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<RootNamespace>some.project.ORM</RootNamespace>
<AssemblyName>some.project.ORM</AssemblyName>
<PublishTargetType>website</PublishTargetType>
</PropertyGroup>
<Import Project="$(SolutionDir)\_Build\props\_PublishTargetType.props" />
<ItemGroup>
<PackageReference Include="Glass.Mapper.Sc.100" Version="5.8.173" />
</ItemGroup>
<ItemGroup>
<Content Update="App_Config\Include\Foundation\Glass\Glass.Mapper.Sc.Start.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>

this issue was because the file that I was copying to was over the 260 limit in VS. My path length was 261. We copied the solution to a shorter path and the build worked fine. thanks for your help.

Related

msbuild PackageReference.PrivateAssets = All does not seem to work

I have a test project which reference NUnit3TestAdapter. I do not this reference to be copied over to the projects that depend on this one.
I thought setting PrivateAssets = All would do it, but apparently I misunderstand how it works, because it does not have the desired effect.
Here is the code:
Rollup\Rollup.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\UITests\UITests.csproj"/>
</ItemGroup>
</Project>
UITests\UITests.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NUnit3TestAdapter" Version="3.11.2">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project>
Directory.Build.rsp
.\Rollup.sln /restore /v:m
After I run msbuild all is built, but I can see NUnit3TestAdapter is in the bin folder for Rollup.
What am I missing?
(https://github.com/Microsoft/msbuild/issues/3996)
PrivateAssets works as expected but the NUnit test adapter NuGet package adds an MSBuild target to the build that adds a few dll files as content items to the project, which then flow transitively through the build - this has the same effect as if you added a text file and set its "Copy to Output Directory" property.
The NUnit3TestAdapter.props contains definitions like:
<Content Include="$(MSBuildThisFileDirectory)NUnit3.TestAdapter.dll">
<Link>NUnit3.TestAdapter.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>False</Visible>
</Content>
You should see these files if you click the "Show All Files" in the Visual Studio solution explorer.
Note that test projects aren't really supposed to be packaged or referenced. They should be leaf projects. The test project templates even contain an <IsPackable>false</…> definition and XUnit's core package also adds it as an imported MSBuild file. The test frameworks expect you to use their abstraction libraries and not runtime assemblies / test adapter packages for projects that share tests or test logic.

How are we supposed to execute package build targets in the new world where nuget packages are consumed through msbuild PackageReference?

I am developing a suite of UI tests using Selenium. One of the run-time dependencies of this suite is the chromedriver.exe, which we are expected to consume through the Selenium.WebDriver.ChromeDriver NuGet package.
The old world
When this NuGet package is imported the following lines are injected into the csproj file:
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Selenium.WebDriver.ChromeDriver.2.44.0\build\Selenium.WebDriver.ChromeDriver.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Selenium.WebDriver.ChromeDriver.2.44.0\build\Selenium.WebDriver.ChromeDriver.targets'))" />
</Target>
<Import Project="..\packages\Selenium.WebDriver.ChromeDriver.2.44.0\build\Selenium.WebDriver.ChromeDriver.targets" Condition="Exists('..\packages\Selenium.WebDriver.ChromeDriver.2.44.0\build\Selenium.WebDriver.ChromeDriver.targets')" />
And it is automatic by the Visual Studio. This covers our bases, making sure the build targets provided by the Selenium.WebDriver.ChromeDriver package are there at the time of the build and running them as needed. The logic inside the build targets file copies/publishes the chromedriver.exe to the right location.
All is green.
The new world.
I consume the same NuGet package as PackageReference in the csproj file. Cool. However, the build targets of that package are no longer executed. See https://github.com/NuGet/Home/issues/4013. Apparently, this is by design.
I could import the targets manually, but the problem is that I will have to hard code the location where the package is restored. It is no longer restored in the packages directory in the solution, but under my windows profile. But there is no property pointing to this location and hard coding it sucks.
So, here is the version that works for me and I hate it:
<PropertyGroup>
<MyPackagesPath>$(UserProfile)\.nuget\packages\</MyPackagesPath>
<SeleniumWebDriverChromeDriverTargets>$(MyPackagesPath)selenium.webdriver.chromedriver\2.44.0\build\Selenium.WebDriver.ChromeDriver.targets</SeleniumWebDriverChromeDriverTargets>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="2.44.0" />
</ItemGroup>
<Target Name="EnsureChromeDriver" AfterTargets="PrepareForRun">
<Error Text="chrome driver is missing!" Condition="!Exists('$(OutDir)chromedriver.exe')" />
</Target>
<Import Project="$(SeleniumWebDriverChromeDriverTargets)" Condition="Exists('$(SeleniumWebDriverChromeDriverTargets)') And '$(ExcludeRestorePackageImports)' == 'true'" />
Overall, the Sdk style projects are absolutely great, but this whole business of running targets from the packages is totally broken, even if it is by design.
What am I missing?
EDIT 1
So, here is the content of the generated obj\UITests.csproj.nuget.g.targets:
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>
<ImportGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<Import Project="$(NuGetPackageRoot)selenium.webdriver.chromedriver\2.44.0\build\Selenium.WebDriver.ChromeDriver.targets" Condition="Exists('$(NuGetPackageRoot)selenium.webdriver.chromedriver\2.44.0\build\Selenium.WebDriver.ChromeDriver.targets')" />
</ImportGroup>
</Project>
Notice the ImportGroup condition is '$(ExcludeRestorePackageImports)' != 'true'. Now, this condition is always false, because ExcludeRestorePackageImports seems to be hard coded to be true in
c:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\NuGet\NuGet.targets
Inspecting binary log confirms this. Plus https://github.com/NuGet/Home/issues/4013 was closed as WontFix.
Or am I still missing something?
If you are running Restore and other targets during the build, you may get unexpected results due to NuGet modifying xml files on disk or because MSBuild files imported by NuGet packages aren't imported correctly.

Linked files location on .Net core in Debug vs Publish

I have a shared.{Environment}.json file that is added as linked files in several .Net core 2.1 projects. When project is build or published file gets copied to output directory, in case of release its fine but on debug it doesn't work as when project run it looks up for that file in project directory not in output directory.
Whats the proper way to solve this issue for both debug and publish?
For linked files, it will not exist under the project directory.
For a workaround, you could try to copy the file with task in csproj like below:
<ItemGroup>
<Content Include="..\MVCPro\shared.{Environment}.json">
<Link>shared.{Environment}.json</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Target Name="CopyLinkedContentFiles" BeforeTargets="Build">
<Copy SourceFiles="..\MVCPro\shared.{Environment}.json" DestinationFolder=".\" SkipUnchangedFiles="true" OverwriteReadOnlyFiles="true" />
</Target>

MSBuild ignores changes inside *.wpp.target

I have following *.wpp.target file:
<PropertyGroup>
<CopyAllFilesToSingleFolderForMsdeployDependsOn>
ExcludeCustomFilesOrFolders;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForMsdeployDependsOn>
</PropertyGroup>
<Target Name="ExcludeCustomFilesOrFolders" BeforeTargets="ExcludeFilesFromPackage">
<ItemGroup>
<ExcludeFromPackageFolders Include="$(MSBuildProjectDirectory)\Media" />
</ItemGroup>
<Message Text="Custom Exclude From %0D Folders: #(ExcludeFromPackageFolders)%0D Files: #(ExcludeFromPackageFiles)" Importance="high"/>
</Target>
If I run it for the first time out of visual studio 17 Media folder is ignored and not published.
After when I comment the line with ExcludeFromPackageFolders node and publish again Media folder is still ignored. It seems that visual studio or msbuild does not refresh changes made inside *.wpp.target file. Do I miss here something or is VS or MSbuild just buggy?
Can you try to add /PROFILE to the linker option? Might fix the problem: https://developercommunity.visualstudio.com/content/problem/136703/wpp-trace-missing-from-pdb-files-in-vs-2017.html
You have to restart visual studio and reload solution everytime you change it. VS caches it.

MSBuild, clear out multiple files in a project

I am getting the following error when trying to clear out files within my project
LC error LC0000: 'Could not find file 'E:\CI\BuildServer\RMS-Transition\Group\dev\Controls\Properties\licenses.licx'.'
My MSBuild task looks like this...
<Target Name="ClearLicenseFiles">
<ItemGroup>
<LicenseFiles Include="..\**\*.licx"/>
</ItemGroup>
<WriteLinesToFile File="%(LicenseFiles.FullPath)" Lines="" Overwrite="true"/>
</Target>
What is going on? It seems to find all of the .licx files just fine but when it goes to write to them, they don't exist... and according to the documentation the WriteLinesToFile task should create the file anyways if it doesn't already exist.
I am starting to believe that this is a bug with MSBuild... the license files are being DELETED not overwritten as you would expect. Someone else has had this issue as well (comment on bottom of this msdn article)
This is my solution... I created a file that is empty named empty.txt right next to my msbuild proj and then copied this file onto the licx files.
<Target Name="ClearLicenseFiles">
<ItemGroup>
<LicenseFiles Include="..\**\*.licx"/>
</ItemGroup>
<Copy SourceFiles="empty.txt" DestinationFiles="%(LicenseFiles.FullPath)"/>
</Target>