ASP.NET deploy package created only when building from the command line - asp.net-mvc

I have an ASP.NET MVC project whose project file I modified to have the following properties so that it would create a deploy package in a subdirectory of the output folder when it builds in the Release configuration:
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DeployTarget>Package</DeployTarget>
<DeployOnBuild>true</DeployOnBuild>
<CreatePackageOnPublish>true</CreatePackageOnPublish>
</PropertyGroup>
When I build the project from the command line as follows:
msbuild projectname.csproj /p:Configuration=Release
Then, the deploy files are packaged up correctly in a subdirectory underneath the Release output. However, if I build the project from within Visual Studio the deploy files and packages aren't created, even if I have the configuration set to Release.

Is it possible you are not under the any CPU playpen in vs? You could probably remove that all together from the conditional.

Related

setup NSIS build in Bamboo

I have to setup build process in Bamboo server. My requirements are,
We have a web-server application [more than 20 web projects, 10 windows service projects, DB scripts, some supported utilities like exe, xml's, code signing certificates, ssl certificates]
We have already build automation in c#, which uses NSIS scripts to generate installer.exe
Our build process has the following steps:
Checkout the source code
Checkout the Utilities
Checkout the NSIS installer source code
Update the source code
Update the Utilities
Update the Product versions in all the Assembly files of all the projects & Wix files
Build all the MSI projects based from the list [Project.xml] -> Once build completed with Code Signing post build CMD, then move to
some [ex: LatestPackage] folder in any [ex: Package] directory
Build all the Web app projects from the list [Project.xml] -> Publish into some [ex: LatestPackage] folder in any [ex: Package]
directory
Build all the support projects for installer from the list [Project.xml]
Copy the "LatestPackage" from "Package" directory to "LatestPackage" folder in "NSIS Installer" directory
Update the Installer source codes
Copy the installer custom assets to respective folder in "Installer" directory [SQL, some exe's]
Update Installer.xml file with the Branding information's in "Installer" directory
Compile Installer.nsi file & Installer package will be generated under Installer directory
Could anyone guide me in right path to achieve this.
1. Need to setup task for each and every projects?
2. Where to keep the files once build completed?
3. How to move the all the projects binaries into another projects directory?
4. How to keep the supported files and copy them to our source code folders?
5. How to maintain the generated build?
Is Bamboo Server Windows based? Can Visual Studio be installed on it?
If yes then you can automate building NSIS installers using MSBuild and Visual & Installer.
Also (if VS is present) there is an option to create NSIS project in Visual Studio and build the installer from it (building the solution from command line).

Executing 'npm install' before publishing ASP.NET MVC 5.0 project

I have an ASP.NET MVC 5.0 application, and I have introduced a package.json file to manage JavaScript packages in my project (I reference the node_modules path in my BundleConfig.cs to pull in the packages).
When I pull down a new version of the project and build it, Visual Studio seems to automatically retrieve the NPM packages (I'm assuming Visual Studio 2017 has built in support for this).
However, when I publish my application, the node_modules folder does not get generated. I added the following build target to my web .csproj file in the hope this would resolve the dependencies on publishing:
<Target Name="PrepublishScript" AfterTargets="PrepareForPublish">
<Exec Command="npm install"/>
</Target>
However, the command doesn't appear to be executed.
The npm command is definitely part of my path (i.e. when I open a command window and type npm it executes).
Any ideas why this isn't working?
Is this even a reasonable approach?
This worked for me:
<Target Name="CustomPostPublishActions" AfterTargets="GatherAllFilesToPublish">
<Exec Command="npm install" WorkingDirectory="$(PublishUrl)"></Exec>
</Target>
$(PublishUrl) appears to be a built-in variable which I used to ensure that the command was executed in the folder where my published files are being output to.
One caveat is that this doesn't really help when it comes to one-click publish with IIS Web Deploy, I'm not sure what I would need to do for that.

MSBuild /t:pack Nuget-Package has always the same Version

I am creating a nuget-package with /t:pack in my TFS-Build. I can't the use Nuget-Pack-Step, because I am using
<TargetFramework>netstandard2.0</TargetFramework>
How can I apply my AssemblyVersion on the Nuget-Package? Because my Assembly-Version is right, but my Nuget version always remains 1.0.0.0.
Note I am using a C# file for my assembly information instead of the .csproj file.
Is there any possibility to it?
Want to share that link.
The MSBuild-integrated Pack target reads its value from MSBuild properties inside the project (PackageVersion to be specific, which is defaulted from Version, which in turn is defaulted to VersionPrefix which in turn may be suffixed by VersionSuffix).
There is out-of-the-box support for reading this value from an assembly attribute since the new project format is meant to generate these assembly attributes from the same configuration that determines NuGet package metadata.
However, you can extend the build by adding a custom target to the csproj file that reads the built assembly's identity during msbuild /t:Pack:
<Project>
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateNuspecDependsOn>$(GenerateNuspecDependsOn);ReadPackageVersionFromOutputAssembly</GenerateNuspecDependsOn>
</PropertyGroup>
<Target Name="ReadPackageVersionFromOutputAssembly" DependsOnTargets="Build">
<GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
<Output TaskParameter="Assemblies" ItemName="PackAssembly" />
</GetAssemblyIdentity>
<PropertyGroup>
<PackageVersion>%(PackAssembly.Version)</PackageVersion>
</PropertyGroup>
</Target>
</Project>
Note that this target will only run on the "full MSBuild", that is msbuild.exe on windows (visual studio developer command prompt) or mono 5.2+ on linux/Mac. This currently does not work for dotnet pack (.NET Core version of MSBuild). UPDATE: This will now work in .NET SDKs 2.1.* and higher since the GetAssemblyIdentity task has been added to the cross-platform version of msbuild in 2018.
With current version of MSBuild it is possible to specify PackageVersion parameter:
msbuild ProjectName.csproj -t:Pack -p:PackageVersion=1.2.3

Cannot restore Nuget Packages in Teamcity

I have an ASP.NET MVC Web Application created in VS2013 and use TeamCity 8.1 for CI.
I'm trying to restore my Nuget packages before building my Visual Studio solution using a Nuget Pack build step in TeamCity and get this error:
The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets"
was not found. Confirm that the path in the <Import> declaration is correct
It's trying to access the targets in the wrong path because I use version 12.0 and not 10.0.
My solution file starts with this lines:
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30501.0
The project file of my MVC project created in VS2013 have a this declaration of VisualStudioVersion
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
...
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
I suppose the declaration of VisualStudioVersion is the reason to why the build step of restoring Nuget packages is accessing the wrong folder. But I'm not sure what the condition in property VisualStudioVersion is evaluated to.
I've tried to create an Environment variable for VisualStudioVersion and set it to 12.0 but that did not work.
The strange thing is if I disable the Nuget Pack step in TeamCity the build step seems to find the correct path
Starting: C:\TeamCity\buildAgent\plugins\dotnetPlugin\bin\JetBrains.BuildServer.MsBuildBootstrap.exe /workdir:C:\TeamCity\buildAgent\work\17b24c83f45b721d "/msbuildPath:C:\Program Files (x86)\MSBuild\12.0\bin\MSBuild.exe"

How to use x64 aspnet_compiler during publish

I have MVC 5 application which is using RazorGenerator.MVC and RazorGenerator.MsBuild. Because of that my MvcBuildViews is set to false, because it is no longer required. The application is .NET 4.5 one in Visual Studio 2012.
When I'm publishing my application with web publish tool (right click on MVC project -> Publish), I'm using option to pre-compile during publishing.
Everything is working very well when I'm using Any CPU or x32 Platform. However when I'm trying to publish x64 application I have an issue with aspnet_compiler.
It is always trying to use: *C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe* one instead of 64 version so my application cannot be published with x64 platform.
The only place I found I can change path is under MvcBuildViews target, but becuase it is always false for me it will never hit this target and AspNetCompiler ToolPath cannot be used.
I'd like to know from where (which targets file or tasks file) contains that path? I've searched all targets I believe and couldn't find from where is taken.
Open the csproj file of the project in your favourite text editor.
Locate:
<MvcBuildViews>true</MvcBuildViews>
Add the following below it:
<AspNetToolPath Condition=" '$(Platform)' == 'x64'">$(windir)\Microsoft.NET\Framework64\v4.0.30319</AspNetToolPath>
Locate:
<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'" >
<AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
</Target>
Amend the AspNetCompiler line as follows:
<AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" ToolPath="$(AspNetToolPath)" />
For Visual Studio 2013, the solution can be found here: Configure Visual Studio 2013 to allow ASPNETCOMPILER to precompile using the x64 compiler (thanks to Nitin)
Shortcut:
Add the following xml in the Project/PropertyGroup xml tag to the publish profile (located in the Properties\PublishProfiles directory of your project).
<AspnetCompilerPath>C:\Windows\Microsoft.NET\Framework64\v4.0.30319</AspnetCompilerPath>

Resources