Why do I get file not found error when publishing angular project using MSBuild

283 Views Asked by At

I have the .NET solution with several api project and 1 web project. This web project is SPA application written on angular 10. In build events of this project I do have following command:

cd $(ProjectDir)web-new-angular
call npm i
call npm run prod-build

so we simply install nuget packages and build the angular project. Nothing specific.

For project deploy publish profiles are used. We have Jenkins pipeline build and another one for deploy. MSBuild and MSDeploy are used correspondingly. Deploying API projects and old web project on angularJs works just fine. But when I try to deploy project written on Angular10 I get very strange exception. I am not even able to publish site locally via Visual Studio

Here is publish profile for local env:

<?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 http://go.microsoft.com/fwlink/?LinkID=208121. 
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <WebPublishMethod>FileSystem</WebPublishMethod>
        <LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
        <LastUsedPlatform>x64</LastUsedPlatform>
        <SiteUrlToLaunchAfterPublish />
        <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
        <ExcludeApp_Data>False</ExcludeApp_Data>
        <publishUrl>C:\inetpub\wwwroot</publishUrl>
        <DeleteExistingFiles>True</DeleteExistingFiles>
        <ExcludeFoldersFromDeployment>web-new-angular\.idea;bin;obj;Properties;web-new-angular\e2e;web-new-angular\node_modules;web-new-angular\out-tsc;web-new-angular\src;</ExcludeFoldersFromDeployment>
        <ExcludeFilesFromDeployment>web-new-angular\*.*</ExcludeFilesFromDeployment>
    </PropertyGroup>
    <Target Name="CollectCustomFiles">
        <ItemGroup>
            <_WebAppFiles Include="web-new-angular\dist\web-new-angular\*.js" />
            <FilesForPackagingFromProject Include="%(_WebAppFiles.Identity)">
                <DestinationRelativePath>web-ui\%(Filename)%(Extension)</DestinationRelativePath>
            </FilesForPackagingFromProject>
        </ItemGroup>
    </Target>
    <PropertyGroup>
        <CopyAllFilesToSingleFolderForPackageDependsOn>
            CollectCustomFiles;
            $(CopyAllFilesToSingleFolderForPackageDependsOn);
        </CopyAllFilesToSingleFolderForPackageDependsOn>

        <CopyAllFilesToSingleFolderForMsdeployDependsOn>
            CollectCustomFiles;
            $(CopyAllFilesToSingleFolderForMsdeployDependsOn);
        </CopyAllFilesToSingleFolderForMsdeployDependsOn>
    </PropertyGroup>

</Project>

When I start file publish the content of my dist folder successfully copied to obj/x64/Debug/Package/PackageTemp so it is identical to what I have in dist. But after that I've get an exception that one of the files is not found:

сonnecting to C:\inetpub\wwwroot... Transformed Web.config using D:\work\ebv_src\Web-UI-new\Web.Debug.config into obj\x64\Debug\TransformWebConfig\transformed\Web.config. Transformed obj\x64\Debug\TransformWebConfig\transformed\Web.config using D:\work\ebv_src\Web-UI-new\Web.LocalTest.config into obj\x64\Debug\ProfileTransformWebConfig\transformed\Web.config. Copying all files to temporary location below for package/publish: obj\x64\Debug\Package\PackageTmp. C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VisualStudio\v16.0\Web\Microsoft.Web.Publishing.targets(3000,5): Error : Copying file web-new-angular\dist\web-new-angular\22.67853f9951adcbd6597b.js to obj\x64\Debug\Package\PackageTmp\web-new-angular\dist\web-new-angular\22.728eb52a2638564d0324.js failed. Could not find file 'web-new-angular\dist\web-new-angular\22.728eb52a2638564d0324.js'.

Strange this is that I do not have such generated file in dist folder. I have built modules js files with similar names, but hash is different. I have no ideas where this file comes from.

[enter image description here]This is how dist folder content looks like. So as you can see there is file 22.[hash].js but hash part is different screenshot

I am able to simply build the project using npm run build-prod command, but I am not able to deploy. When I use publish profile for environment other from local - I use Package in publish profile. And I get the same exception on build stage.

When I simply try to search for part of name of not found file I found reference to it in DesignTimeResolveAssemplyReferenceInput.cache that is automatically created in obj/x64/Debug folder

Any ideas?

0

There are 0 best solutions below