i create a blank new ASP.Net Core with Angular from VS 2017 (in my Document folder) and i try to build it i always get this error:
VS2017 Error
If i create a blank new asp.net without Angular it works fine.
It somehow has a error with the cmd.exe but i cant figure out why. The path to the cmd.exe is correct, launched VS with administrator privileges, notejs is installed, opening the .cspoj Line 33 (output TaskParameter...) and executing the command works too.
<Exec Command="node --version" ContinueOnError="true">
<Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
</Exec>
After executing the following command manually in the CMD (from the .csproj) the error didnt come anymore while building, rebuilding.
<Target Name="DebugRunWebpack" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('wwwroot\dist') ">
....
<Exec Command="node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js" />
<Exec Command="node node_modules/webpack/bin/webpack.js" />
</Target>
Related
I'm stuck and I can't find really anything in searching. I have a standard ASP.Net web project (framework 4.8) in Visual Studio 2019. This is not a core.net app. What I want to do is to execute a command after I publish the app to a folder. In the .csproj file I am able to perform an action just before the files are copied by adding this in --
<Target Name="CustomPostPublishAction" AfterTargets="CopyAllFilesToSingleFolderForPackage">
<Exec Command="..\MyProject.Build\Build.bat" />
</Target>
But I would like to execute a command after it publishes my files out to the folder. I've tried this
<Target Name="CustomAction" AfterTargets="Publish">
<Exec Command="..\MyProject.Build\AfterPublish.bat" />
</Target>
and
<Target Name="CustomAction" AfterTargets="AfterPublish">
<Exec Command="..\MyProject.Build\AfterPublish.bat" />
</Target>
Neither of these work. Any ideas?
Im setting up a Azure devops build pipeline for a .NET core 2.2 web app that includes Angular and one of the steps it runs is dotnet publish. However, the end result is not what i was expecting compared to when running a publish directly from VS 2017.
As a way to run custom npm commands to target specific environments. So in my csproj file I have this
<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
<!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
<!-- Use conditional builds based on build target setting eg. debug, dev, prod etc -->
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build " Condition=" '$(Configuration)' == 'Debug' " />
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build --prod false --configuration=dev" Condition=" '$(Configuration)' == 'Test' " />
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build --prod true --configuration=prod" Condition=" '$(Configuration)' == 'Release' " />
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build:ssr --configuration=prod" Condition=" '$(BuildServerSideRenderer)' == 'true' And '$(Configuration)' == 'Release' " />
However, the devops build was not running the correct command. After looking at the build log, it was simply running ng build, not including the extra flags to target a specific config.
So then to confirm this, I ran at a command line
dotnet publish -c Test
, and sure enough, the output indicated it ran ng build, without seemingly using what was in the csproj file.
How then can I get my npm command to take the configuration values like those in the csproj file but when dotnet publish runs?
Instead of trying to get parameters working through MSBuild, I'd recommend moving your npm commands into package.json like this.
"scripts": {
"buildTest": "npm run build --prod false --configuration=dev",
"buildProd": "npm run build --prod true --configuration=prod"
}
And then use csproj to just run npm run buildTest and npm run buildProd and so on.
My *.csproj configuration is following:
<Target Name="BeforeBuild">
<Exec Condition="$(Configuration) == 'Debug'" Command="npm run buildDev" />
<Exec Condition="$(Configuration) == 'Release'" Command="npm run buildProd" />
</Target>
When hitting the "Publish" button (Release config - to file system) the command is executed, but the files which are newly created by webpack are not copied to the publish target location:
<Content Include="dist\**" Exclude="dist\**\*.js.map" />
Is there a way to run npm script before publish picks up the files for release?
I've seen this fixed for .net core 2.0+, but how about ASP.NET?
Might not be the best solution, but I've found that the following configuration will do the job:
<PropertyGroup>
<CompileDependsOn>
$(CompileDependsOn);
WebpackBuild;
</CompileDependsOn>
</PropertyGroup>
<Target Name="WebpackBuild" DependsOnTargets="CompileTypeScript">
<Exec Condition="$(Configuration) == 'Release'" Command="npm run buildProd" />
</Target>
<Target Name="BeforeBuild">
<Exec Condition="$(Configuration) == 'Debug'" Command="npm run buildDev" />
</Target>
I use webpack in my asp.net Core MVC to bundgle js/css files and put it into the wwwroot folder after.
My folder structure looks like this on the screen:
I added "after-build" section into FrontEnd.csproj:
<Target Name="BuildClientAssets" BeforeTargets="Build">
<Exec Command="npm install"/>
<Exec Command="npm run build"/>
</Target>
FrontEnd/node_modules contains npm modules loaded by "npm install" command;
Web/wwwroot/dist and Web/wwwroot/fonts contains bundled js/css/fonts files, generated by "npm run build" command;
It works as expected. But it would be great if I had an oppurtunity to exec this command on publish web project.
But when I try to add prepublish section into the Web project and start publish
<Target Name="BuildClientAssets" BeforeTargets="Publish">
<Exec Command="npm install"/>
<Exec Command="npm run build"/>
</Target>
I get this error: The command "npm run build" exited with code -4058
I supposed, that it is because of the package.json located in FrontEnd project (not in the Web project), so I looked for a suitable script to start command in right way and overrrided the section:
<Target Name="BuildClientAssets" BeforeTargets="Publish">
<Exec Command="npm install" />
<Exec Command="webpack --config ../FrontEnd/webpack.config.js" />
</Target>
But after I get errors such as:
Can't resolve './src/components/app/file1.ts'
ERROR in Entry module not found 0
Error Can't resolve './src/components/app/file2.ts'
ERROR in Entry module not found 0
Error Can't resolve 'source-map-loader'
Module not found 0
The command is started but modules are searched still in the Web, not the FrontEnd project.
Any idea?
The npm install isn't hitting the right folder either, you need run these commands inside the right location - probably worked in your machine because it already have the node-modules. You can keep both commands (Çıpm install / npm run build) and try to target the right location. How you can do that? You could inform the command the folder he will run.
First, set in the PropertyGroup section the front-end folder location
<FrontRoot>../FrontEnd/</FrontRoot>
and pass the property in the command lines using the WorkingDirectory property. It will looks like this:
<Target Name="BuildClientAssets" BeforeTargets="Publish">
<Exec WorkingDirectory="$(FrontRoot)" Command="npm install"/>
<Exec WorkingDirectory="$(FrontRoot)" Command="npm run build"/>
</Target>
There is a similar situation here
I am trying to simplify the deployment for one of our web projects by supplying an installer that takes care of everything the application needs to be initialized. I've chosen the WiX toolset for this and created a custom build script following this and partly this tutorial. To reproduce the problem I am facing, you can download the sources of the first tutorial link.
My general goal is to be able to create an installer directly from Visual Studio. The tutorial describes how to write a build script that generates the installer. Basically I want to invoke this script by clicking "Build" within Visual Studio (2012, if it matters).
First I've added a WiX project to the solution (relocate it to the setup-directory!). I've added all the setup-files and the required WiX references (UI, Util, IIS, SQL). By simply invoking the build now, WiX complains about an undefined var.publishDir variable. So I ran the supplied build script using the following command inside the VS developer console:
msbuild /t:Build;CreateInstaller;DeleteTmpFiles build_setup.build
First this gave me an error 9009 (command not found) when trying to invoke the heat tool for harvesting. I fixed this by replacing the "$(WixPath)heat" call with "$(WiX)\bin\heat". After that everything worked as desired, so I started hooking into the build process of the .wixproj file in order to call the build script from there. I did this by defining the following build targets (right below the item groups):
<Target Name="Build">
<MSBuild Projects="build_setup.build" Targets="Build;CreateInstaller" Properties="" />
</Target>
<Target Name="Rebuild">
<MSBuild Projects="build_setup.build" Targets="Build;CreateInstaller;DeleteTmpFiles" Properties="" />
</Target>
<Target Name="Clean">
<MSBuild Projects="build_setup.build" Targets="DeleteTmpFiles" Properties="" />
</Target>
Also I checked, if the installer project is excluded from solution-wide builds inside the build configuration manager for all configurations (but especially Release|AnyCPU since this is the desired configuration for deployment). For sake of clarity I've fixed both MSBuild calls within the build_setup.build script and added my desired platform:
<!-- Define default target with name 'Build' -->
<Target Name="Build">
<!-- Compile whole solution in release mode -->
<MSBuild Projects="..\MyWeb\MyWeb.sln" Targets="ReBuild"
Properties="Configuration=Release;Platform=Any CPU" />
</Target>
<!-- Define creating installer in another target -->
<Target Name="CreateInstaller">
<RemoveDir Directories="$(PublishF)" ContinueOnError="false" />
<MSBuild Projects="..\MyWeb\MyWeb\MyWeb.csproj" Targets="ResolveReferences;_CopyWebApplication"
Properties="OutDir=$(Publish)bin\;WebProjectOutputDir=$(Publish);Configuration=Release;Platform=AnyCPU" />
<!-- ... -->
</Target>
Now when I invoke the build by right-clicking the installer project and "Build", the build is successfully triggered from Visual Studio - exactly what I want.
The problem begins with adding project references: I've added a new library project (defined a simple class in there, referenced the library from the website and created an instance of the library class there). As soon as I try to build the project from Visual Studio now, I get an error that the referenced assembly cannot be copied from the publish-directory, because it does not exist:
Microsoft.WebApplication.targets(175,5): error MSB3030: Could not copy file "...\WixWebDeploy\Setup\publish\bin\MyWeb.Model.dll" because it was not found.
The strange thing is, that everything works fine, if I invoke the build script from the developer console! Also this only affects project references (the project is published using the targets ResolveReferences and _CopyWebApplication). NuGet packages or static library references are copied without any problems.
I appreciate any ideas that point me into the right direction to tackle down this issue. For example I am interested in the difference between calling msbuild from console or Visual Studio (if there is any...). Thanks in advance!
I finally figured out how to fix this issue. The solution was to use OutputPath argument instead of OutDir call a command line script from MSBuild:
<Target Name="Build">
<Exec Command="echo Building solution with '$(MSBuildToolsPath)\msbuild'..." />
<!--<MSBuild Projects="build_setup.build" Targets="CreateInstaller" Properties="Configuration=Release;Platform=AnyCPU" />-->
<Exec Command="call build_setup.cmd $(MSBuildToolsPath) CreateInstaller" />
</Target>
<Target Name="Rebuild">
<Exec Command="echo Building solution with '$(MSBuildToolsPath)\msbuild'..." />
<!--<MSBuild Projects="build_setup.build" Targets="Build;CreateInstaller" Properties="" />-->
<Exec Command="call build_setup.cmd $(MSBuildToolsPath) Build CreateInstaller" />
</Target>
<Target Name="Clean">
<Exec Command="echo Building solution with '$(MSBuildToolsPath)\msbuild'..." />
<!--<MSBuild Projects="build_setup.build" Targets="DeleteTmpFiles" Properties="" />-->
<Exec Command="call build_setup.cmd $(MSBuildToolsPath) DeleteTmpFiles" />
</Target>
From the build_setup.cmd I call MSBuild again:
if [%1] == [] (
echo "Please supply the msbuild directory as first argument!"
exit 10
) else (
set MSBUildDir=%1
)
if [%2] == [] (
echo "You have to supply at least one of the following arguments: Build, CreateInstaller, DeleteTmpFiles!"
exit 11
) else if [%3] == [] (
echo "%MSBUildDir%\msbuild /t:%2 setup.build"
call %MSBUildDir%\msbuild /t:%2 setup.build
exit 0
) else if [%4] == [] (
echo "%MSBUildDir%\msbuild /t:%2;%3 setup.build"
call %MSBUildDir%\msbuild /t:%2;%3 setup.build
exit 0
) else (
echo "%MSBUildDir%\msbuild /t:%2;%3;%4 setup.build"
call %MSBUildDir%\msbuild /t:%2;%3;%4 setup.build
exit 0
)
This seams kinda redundant and maybe somebody got a better suggestion.