How to use x64 aspnet_compiler during publish - asp.net-mvc

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>

Related

Disable typescript in visual studio sometime not working

I have merged Angular 2 CLI app with .NET MVC application. I use ng commands to build the application and VSCode for Angular and Visual Studio for .NET Code. I want to disable the Typescript compilation by Visual Studio so that Visual Studio should not care about typescript errors.
To Disable typscript compilation by Visual Studio I have edited .csproj project file and added below code (refer)
<PropertyGroup>
<!-- Disables TypeScript compilation -->
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
</PropertyGroup>
Comment line below and add new one
<!--<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets')" />-->
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" Condition="False" />
Its works fine, but some time start giving typescript errors in visual studio as below(screenshot).
To make errors go away, I do which sometime works:
Clean Solution and Build
Restart Visual Studio
I don't know any better solution for this, any suggestions ?

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

Sharing code between ASP.NET MVC project and Cordova project

I am developing a Cordova based mobile app via Visual Studio's Cordova template as well as an ASP.NET MVC web application in the same Visual Studio solution. I'd like to be able to share as much HTML between both projects as possible. One issue I am running into is the bundling and minification that takes place in ASP.NET that is not available in the Cordova project. Any ideas how I could support minification within Visual Studio across both projects that would allow me to share as much code as possible?
Cordova's project file .jsproj is an ordinary build file that is handled by MSBuild, so you can apply whatever processing logic you need by adding custom targets. You can even run tools from Node.js world like Grunt or Gulp by installing respective VS extensions.
As to sharing code between ASP.NET and Cordova projects, I suggest adding links in your .jsproj, as follows:
<PropertyGroup>
<AspNetProject>C:\YourAspNetProject</AspNetProject>
</PropertyGroup>
<ItemGroup>
<Content Include="$(AspNetProject)\Views\**\*.cshtml">
<Link>views\%(RecursiveDir)%(FileName).html</Link>
</Content>
<!-- add other links here -->
</ItemGroup>
This way VS displays the linked files in Solution Explorer and allow you to edit them as if they were local.
Unfortunately, the current version of VS Tools for Apache Cordova, CTP3, does not support linked items, so another change has to be made in your .jsproj:
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CordovaTools\vs-mda-targets\Microsoft.MDA.targets" />
<PropertyGroup>
<BuildDependsOn>PreBuild;$(BuildDependsOn)</BuildDependsOn>
</PropertyGroup>
<Target Name="PreBuild">
<ItemGroup>
<LinkedFiles Include="#(Content)" Condition="'%(Content.Link)' != ''" />
<!-- add other links here -->
</ItemGroup>
<Copy SourceFiles="%(LinkedFiles.Identity)" DestinationFiles="%(LinkedFiles.Link)" />
</Target>
The PreBuild task is called before any Build subtask and copies the linked files to your Cordova's project. The rest of the build process runs as usual.

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"

Why does a Visual Studio 2008 web deployment project create unwanted files?

Why does my web deployment project, when compiled, create a Visual Studio project file and a bunch of other unwanted/unneed files in the release and debug folders?
The debug files are also being included even though I have the "Generate debug information" option unchecked when in release mode.
I'm also getting some obj folder that contains another set of debug and release folders that seem out of place.
In short, it's creating a lot of non-release files. I am using a ASP.NET MVC project, but I don't think that should make a difference.
By default Visual Studio generates PDB files in both debug and release mode. The difference is that in debug mode the entire symbol table is loaded while in release mode only the key symbols are loaded.
You can completely disable PDB generation in release mode by setting generate debug info in advanced compile options to none.
If you want to have a clean output folder you can add the following ItemGroup to your web deployment project's file (.wdproj):
<ItemGroup>
<ExcludeFromBuild Include="$(SourceWebPhysicalPath)\obj\**\*.*" />
<ExcludeFromBuild Include="$(SourceWebPhysicalPath)\**\*.csproj" />
<ExcludeFromBuild Include="$(SourceWebPhysicalPath)\**\*.scc" />
<ExcludeFromBuild Include="$(SourceWebPhysicalPath)\**\*.user" />
<ExcludeFromBuild Include="$(SourceWebPhysicalPath)\**\*.vspscc" />
</ItemGroup>

Resources