I am checking out the default MVC 6 application and published the build on local file system. This how it looks like when i check Compile source files to nuget pacakges
I can see 3 main folders: approot, logs & wwwroot
Inside approot:
I can see that my WebApplication1 is now as a nuget package.
What is ef file in approot>Packages>WebApplicaton1>1.0.0>app ?
ef files are in approot too along with 2 web files. What are they ?
Inside wwwroot: It has all my static resources like css and js.
How does all this fall in place when we deploy the application in IIS or azure ?
The ef and web files in the published output correspond to the ef and web commands that you have defined in your project.json file. You could define more commands in your project.json file and all of them would show up here.
Starting with beta-8 version, ASP.NET 5 uses a module in IIS called HttpPlatformHandler which forwards http requests to a external process...in our case it would be the dnx.exe process. For example, you can take a look at the following web.config file under wwwroot which shows the module registration and also the path to execute the external process...as you can see here web.cmd is being used.
<configuration>
<system.webServer>
<handlers>
<add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
</handlers>
<httpPlatform processPath="%home%\site\approot\web.cmd" arguments="" stdoutLogEnabled="false" stdoutLogFile="\\?\%home%\LogFiles\stdout.log"></httpPlatform>
</system.webServer>
</configuration>
This kind of design is suitable for non-Windows scenarios too...for example, you could use your app with the nginx reverse proxy too
More deeper details can be found in the following link:
Change to IIS hosting model
Related
I have rather strange problem.
One of the applications we are working on stopped working after publish to Azure Web App. Everything works ok locally. After long investigation, the culprit is that the web.config generated by the build (in VSTFS) has this:
<aspNetCore processPath=".\SomeServiceName.Api " stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
While the correct one is:
<aspNetCore processPath=".\SomeServiceName.Api.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
Note the missing .exe.
The build output of the project is set to Console Application. It's ASP.NET Core app, running on full framwork. The build is run using Visual Studio Build task in VSTS, with following MSBuildArguments:
/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)"
If I run the build on my dev machine, using MSBuild cli, with the same command line arguments, I get this:
<aspNetCore processPath="dotnet" arguments=".\SomeServiceName.Api.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
The project is using <Project Sdk="Microsoft.NET.Sdk.Web">.
I'm guessing I could just add web.config to the project (it's not there at all now) and have it in source control the way I want, that should fix my immidiate problem of broken deployments. But I would like to know:
The web.config genrated by build on VSTS is obviously wrong. Is that a bug in Microsoft.NET.SDK.Web thing?
I don't have access to the actuall build server. I'm guessing that the only reasonable explanation is that someone updated .net core SDK, which is why the behaviour changed. Does this make sense? Does the msbuild targets come from .NET Core SDK, or is that part of visual studio?
I'm getting different web.config on my machine. Why is that?
Update:
For anyone who stumbles here, here's the link for issue on github:
https://github.com/aspnet/websdk/issues/408
Looks like this is now fixed and will be part of some release some day (No idea what's the release cycle though).
I had exactly the same problem, and I solved it last week.
We had 2 ASP.Net Core projects, one showing the issue, the other didn't have the issue. So we compared the 2 .csproj files.
Turns out that in our case, all we needed to do was delete the
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
properties from the .csproj; once that was done, MSBuild correctly created the web.config, including the .exe at the end of the processPath.
I had exactly the same problem, and I solved it last week. We had 2 ASP.Net Core projects, one showing the issue, the other didn't have the issue.
Firstly check C:\Program Files\dotnet path, if the 'sdk' folder is not available then you need to install the ASP.NET Core SDK. If you install this package then the problem is resolved and the app is running with:
<aspNetCore processPath="dotnet" arguments=".\yourapp.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout"/>
A few options for getting the .exe in there. Each of these methods worked for me:
Switch the build configuration from Debug (the default) to Release:
dotnet publish -c Release or msbuild argument /p:Configuration=Release
Create a web.config the way you want it in the root of your project and then tell the SDK not to touch it by adding the following to your project file:
<PropertyGroup>
<IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>
</PropertyGroup>
Specify your target runtime as one of the win-* runtimes listed at https://learn.microsoft.com/en-us/dotnet/core/rid-catalog. Here's the code that appears to be adding the exe extension:
https://github.com/aspnet/websdk/blob/6b898ad0a39329ab5f0db281a9c1712e4303ed61/src/Publish/Microsoft.NET.Sdk.Publish.Targets/netstandard1.0/TransformTargets/Microsoft.NET.Sdk.Publish.TransformFiles.targets#L44
Overview
I am building a deployable web package that can be imported into IIS that automatically prompts for settings needed by my ASP.NET Core application. I already created a package that will deploy just fine, except after deploying, I need to manually find/edit my appsettings.json file.
I know this package can include a parameters.xml file that will automatically prompt and fill in my appsettings.json when importing an app into IIS. I have already made a parameters.xml file, and manually added it to my package after building it; it worked as expected. I'd just like to have msbuild automatically add the parameters.xml file to the package for me.
A separate project of mine (ASP.NET MVC 4) already does this. For that, I simply needed to put my parameters.xml in the same folder as my .csproj. I tried doing the same here, but had no luck.
Repro Steps
I created an ASP.NET Core Web Application
Using .NET Framework on ASP.NET Core 1.1
I then went to publish my website
Selected 'Folder' (just to get a template)
I then edited the profile and changed the WebPublishMethod to Package and added the three lines below it.
<DesktopBuildPackageLocation>bin\$(Configuration)\$(MSBuildProjectName).zip</DesktopBuildPackageLocation>
<PackageAsSingleFile>true</PackageAsSingleFile>
<DeployIisAppPath>External</DeployIisAppPath>
I then published one more time. Now I get a WebDeploy package that I can deploy to IIS.
Great! but...
I'd like to customize the parameters.xml.
For previous projects, I was able to add a parameters.xml file to my project root, and VS/msbuild would automatically add it to my published package. This currently works for a different project using ASP.NET MVC 4.
So, I tried the same thing for this project. First I added a settings.json with a very simple setting:
{
"SettingName": ""
}
Then I added a parameters.xml file that I know works to my project root. (If I manually replace the parameters.xml file in Sample.zip package, it correctly prompts and replaces my setting when deploying)
<parameters>
<parameter name="IIS Web Application Name" value="External" tags="IisApp">
<parameterEntry kind="ProviderPath" scope="IisApp" match="^c:\\users\\joshs\\documents\\visual\ studio\ 2017\\Projects\\Sample\\Sample\\obj\\Release\\net461\\win7-x86\\PubTmp\\Out\\$" />
</parameter>
<parameter name="Setting Name" description="Enter a custom app setting" defaultValue="Default Setting Value">
<parameterEntry kind="TextFile" scope="obj\\Debug\\net461\\win7-x86\\PubTmp\\Out\\appsettings\.json$" match="(?<=\"SettingName\"\s*:\s*\")[^\"]*" />
</parameter>
</parameters>
Again, I right click and Publish once more. This time with the parameters.xml file.
I expect the Sample.zip to contain the parameters.xml that I added to my project root, but it does not. It is the exact same as from my original publish.
Question
During the build process when creating a web deploy package, how do you include custom settings in the parameters.xml?
I have already tried this...
I already looked at https://stackoverflow.com/a/46338042/2494785, but with no luck, though my command differed slightly from the original poster.
PS C:\Users\joshs\Documents\Visual Studio 2017\Projects\Sample> & 'C:\Program Files (x86)\Microsoft Visual Studio\2017\E
nterprise\MSBuild\15.0\Bin\MSBuild.exe' .\Sample.sln /t:Sample /p:DeployOnBuild=true /p:PublishProfile=FolderProfile /p:
ProjectParametersXMLFile="C:\Temp\parameters.xml"
I was able to solve this from peteawood's comment from an issue posted on GitHub.
https://github.com/aspnet/websdk/issues/201#issuecomment-349990389
In ASP.NET Core 2.0+ you can add the following to your .csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
.
.
<Target Name="AddMoreParameters" AfterTargets="_CreateParameterFiles">
<Copy SourceFiles="Parameters.xml" DestinationFiles="$(_MSDeployParametersFilePath)" />
</Target>
</Project>
SourceFiles should point to the location of your parameters.xml file from the perspective of the .csproj file. My parameters.xml is found in the same directory as my project file.
I believe I can just pass parameters via cmd-line as properties for msbuild.
It's not fully what you asked for I understand.
For example, in the following command I'm passing DeployIisAppPath property:
dotnet publish /p:WebPublishMethod=Package /p:DeployIisAppPath=mysite/myapp /p:PublishProfile=rnddev03-core-dev
and in the output folder we'll get xxx.SetParameters.xml file with:
<parameters>
<setParameter name="IIS Web Application Name" value="mysite/myapp" />
</parameters>
I am trying to find a way to run MVC6 application on IIS but without actually doing the publish. I am not sure if that is possible, and if not will it be possible in the future?
I would like to have similar behavior like on previous versions where I could easily debug my code and make changes while the application is running under IIS.
From your original question (emphasis added):
I am trying to find a way to run MVC6 application on IIS but without actually doing the publish.
From your comment to tugberk (emphasis added):
Right now every time when I make a change I need to call that dnu publish command in order to see my changes on IIS. I would like to see them only by doing rebuild.
Answer and reasons
You'll need to publish. There are at least two reasons:
IIS needs build output and
IIS needs a web.config file.
IIS might need a few other things too, about which I'm not aware. So, you'll need to publish. This isn't a big deal: after the onetime setup, publish doesn't take much longer than rebuild does.
Why do you need to publish?
In Visual Studio 2015, if you build an ASP.NET 5 web app, there will be no build output under your solution's directory, and IIS needs build output. By default Roslyn only runs code analysis without emitting build output.
You can change that default, so that Roslyn does emit build output, but that won't produce the web.config file that IIS needs. By going to View > Project Properties > Build and checking "Produce outputs on build", Roslyn will emit output to the artifacts directory. E.g:
artifacts/bin/MyWebApp/Debug/MyWebApp.1.0.0.nupkg
artifacts/bin/MyWebApp/Debug/MyWebApp.1.0.0.symbols.nupkg
artifacts/bin/MyWebApp/Debug/app/project.json
artifacts/bin/MyWebApp/Debug/dnx451/MyWebApp.dll
artifacts/bin/MyWebApp/Debug/dnx451/MyWebApp.pdb
artifacts/bin/MyWebApp/Debug/dnx451/MyWebApp.xml
artifacts/bin/MyWebApp/Debug/dnxcore50/MyWebApp.dll
artifacts/bin/MyWebApp/Debug/dnxcore50/MyWebApp.pdb
artifacts/bin/MyWebApp/Debug/dnxcore50/MyWebApp.xml
If you point IIS at the artifacts directory, you'll now have the problem of having neither a wwwroot nor a web.config.
So, you need to publish (or work out some other convoluted solution) for IIS to work with ASP.NET 5. There is a onetime setup if you want to publish from Visual Studio to a local IIS website. After the onetime setup, you can make changes to your code and publish in two clicks. Here's the onetime setup:
Right click the project.
Choose Publish.
Select File System and add a profile name (e.g. inetpub).
Change the target location to C:\inetpub\MyWebApp
In Settings, select appropriate settings. E.g.
Configuration: Debug
Target DNX Version: dnx-clr-win-x64.1.0.0-beta4
Click Publish.
Once publish completes, point IIS at C:\inetpub\MyWebApp\wwwroot and you will be able to browse to the web site. Further to the point, you can now change your code, publish in two clicks, and refresh your IIS site to see the changes.
Some gotchas
If you do choose to publish to inetpub, be sure to run Visual Studio as administrator, lest you receive an insufficient permissions error.
If you accept the default publish location (instead of using inetpub as shown above) watch out for path too long errors (i.e. > 260 characters.)
Final thoughts
Why not use Visual Studio and Debug > Start without debugging during development. With Roslyn and Visual Studio 2015, you can make changes to the code and see those changes by refreshing the web browser. No rebuild is necessary. It's a much nicer workflow.
It's possible. Under the root of your project (project.json directory), run the following command:
dnu publish --runtime active --out bin/artifacts
Once the publish is done, you have some stuff under bin/artifacts folder. Point IIS application pool to bin/artifacts/wwwroot folder we have just created and it should work. Keep in mind that you at least need .NET 4.5.1.
I'm assuming this is a development on IIS question. It's doable but it requires some work. The reason IIS doesn't work out of the box without a publish is because there is no user profile setup on app pools by default. The simplest thing you can do is to enable the user profile on the app pool, that will allow IIS to find the runtime in the user profile folder. On top of that, you require a web.config to specify which version of the runtime to use (dnu publish generates this for you so if you want, you can do a publish and copy the runtime folder). After doing that, pointing IIS to the wwwroot should just work (assuming you setup the right web.config with the right runtime and the right bitness).
You also need the correct AspNet.Loader.dll in the bin folder. If you use visual studio, it'll copy it in the right place.
Based on davidfowl answer i ran ASP.NET MVC6 on IIS without publishing application. But i still can't start debug it by F5(only by attaching to w3wp.exe).
Anyway i hope it would be helpful:
In the root of the project add "packages" directory(or name it whatever you like).
In global.json file add "packages": "packages". e.g.:
{
"projects": [
"src",
"test",
"wrap"
],
"sdk": {
"version": "1.0.0-beta4"
},
"packages": "packages" // <--
}
Packages will be now stored in this directory.
Create a "runtimes" directory in the root of your project.
Copy a runtimes from %userprofile%/.dnx/runtimes to /path/to/your/project/runtimes
Create a web.config in wwwroot of you project. e.g.:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="bootstrapper-version" value="1.0.0-beta4" />
<add key="dnx-version" value="1.0.0-beta4" />
<add key="dnx-clr" value="clr" />
<add key="dnx-app-base" value=".." />
<add key="runtime-path" value="../../../runtimes" />
</appSettings>
</configuration>
Create web application in IIS and point it to your project wwwroot.
My project directory structure:
Projects/
vNext/
packages/
runtimes/
dnx-clr-win-x64.1.0.0-beta4/
dnx-clr-win-x86.1.0.0-beta4/
...
src/
vNext/
wwwroot/ <-- IIS web application points here
web.config
...
project.json
...
global.json
vNext.sln
...
After this you will be able to attach to w3wp.exe and debug your application running under IIS.
In several projects’ App.config file, there is a line
<add key="url" value="http://www.example.com/"/>
Upon each build, I want to have a task to verify that the "url" key does not have the text "http://localhost". Is there a way to do this?
I'm assuming you have a team, and some of your team members inadvertently checkin those configs, changing that value to localhost.
If this is the case, why not have transform files for each environment, where your debug configuration can set the key to localhost, and your production/test/stage/qa/whatever configuration can set it to example.com or something else.
You might not have been aware that msbuild can transform your config files. Essentially you have your main config file, and then a config file containing just the things changed, for each environment. Upon doing a build, msbuild will modify the main one with whatever the changes are in the other "transform" files.
App.Config Transformation for projects which are not Web Projects in Visual Studio 2010?
Your transform file would look like:
<?xml version="1.0"?>
<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key="url" value="http://www.example.com/" xdt:Locator="Match(key)" xdt:Transform="SetAttributes"/>
</appSettings>
</configuration>
The microsoft link is to http://msdn.microsoft.com/en-us/library/dd465326(VS.100).aspx
They can easily be used on web.configs, as well as app.configs, with a little tweaking to your project file.
An alternative solution would be to integrate unit tests as part of your build, and have the test verify the key in your web.config.
Go to your builds:
Right click on your build and click on edit build definition:
Choose process:
Now we can set fail on build here:
Salvete! Whilst searching for a quality, free asp.net/ajax upload control, I found NeatUpload. I cannot find an online demo for it, but the download package does come with a demo. I need some help installing it on my server (Windows Server 2008).
I followed the directions at http://mumblestiltskin.blogspot.com/2009/10/using-neatupload-simple-setup.html (they are basically the same as the directions in the manual.htm that comes with the NeatUpload binary package).
So far, I have
Successfully installed Brettle.Web.NeatUpload.dll to the GAC using
gacutil.
Added the reference in my web.config (with version and guid)
copied the demo file and its code-behind to my web application (which
is registered in iis7)
Now, when I browse to the page, I get an asp.net server error on
Line 35: protected MultiFile multiFile;
Line 36: protected MultiFile multiFile2;
Line 37: protected InputFile inputFile;
and
error CS0246: The type or namespace name 'MultiFile' could not be found (are you missing a using directive or an assembly reference?)
error CS0246: The type or namespace name 'MultiFile' could not be found (are you missing a using directive or an assembly reference?)
error CS0246: The type or namespace name 'InputFile' could not be found (are you missing a using directive or an assembly reference?)
error CS0246: The type or namespace name 'InputFile' could not be found (are you missing a using directive or an assembly reference?)
error CS0246: The type or namespace name 'ProgressBar' could not be found (are you missing a using directive or an assembly reference?)
error CS0246: The type or namespace name 'ProgressBar' could not be found (are you missing a using directive or an assembly reference?)
What do I do now? Do I need to copy another dll somewhere, or certain files? I can't figure it out from the documentation.
Figured it out! I am deploying the control to a sharepoint web application. (Below, consider SPVD as "Sharepoint Application's Virtual Directory".) If you are not deploying to a Sharepoint website, then you will use the root of your web application's virtual directory where I have used Sharepoint's instead. Here are the steps I followed to get the demo page to run on my server.
Firstly, configuration is different if you use a "web-application" instead of a "web-site". I won't go into the difference here. But in my example, I am configuring a simple "web-site".
I had to:
Copy Brettle.Web.NeatUpload.dll into the GAC on the server (it seems that on Windows Server 2008, you don't have to use the gacutil - just copy the dll into %windir%\assembly. Also note that you must do this on the server; it doesn't work right if you try to do it over a network share). If you don't do this, the NeatUpload Demo just won't do anything. You will have to restart the website in IIS after you do this.
Some of the guides say you need to update the web.config to display the appropriate version and guid, but I found that I didn't have to do that (you will see my web.config below) - UNLESS - you want to use neatupload's section configuration in web.config. So, it is better just to do it right, you know.
The guides also say to use the guid and version number in the aspx pages, like demo.aspx, So, replace this:
<%# Register TagPrefix="Upload" Namespace="Brettle.Web.NeatUpload" Assembly="Brettle.Web.NeatUpload" %>
with this:
<%# Register TagPrefix="Upload" Namespace="Brettle.Web.NeatUpload" Assembly="Brettle.Web.NeatUpload, Version=1.3.3798.663,Culture=neutral, PublicKeyToken=c95290d92c5893c8" %>
Copy the entire directory at NeatUpload-1.3.25\dotnet\app\bin to SVPD\bin. It contains the following items:
Brettle.Web.NeatUpload.dll (the same as the one you installed to the GAC)
Brettle.Web.NeatUpload.GreyBoxProgressBar.dll
Brettle.Web.NeatUpload.HashedInputFile.dll
Hitone.Web.SqlServerUploader.dll
a directory called en-US (with a dll in it)
another direcotry called fr (with a dll in it)
several .mdb databases, and Brettle.Web.NeatUpload.xml
Add the references to the http modules to the web-application's web.config file (see web.config sample below).
Now, you need to copy the directory: NeatUpload-1.3.25\dotnet\app\NeatUpload to SPVD, and leave it named NeatUpload, so that you have SVPD\NeatUpload with all its original contents. Now, in that folder, there are two files you need to edit: Progress.aspx and SmoothProgress.aspx. In the guides, I was told to use the guids and version numbers in the # declarations, such as this:
<%# Page language="c#" AutoEventWireup="false" Inherits="Brettle.Web.NeatUpload.ProgressPage,Brettle.Web.NeatUpload,Version=1.3.3519.18793,Culture=neutral,PublicKeyToken=C95290D92C5893C8" %>
<%# Register TagPrefix="Upload" Namespace="Brettle.Web.NeatUpload" Assembly="Brettle.Web.NeatUpload, Version=1.3.3798.663,Culture=neutral, PublicKeyToken=c95290d92c5893c8" %>
Here is the web.config I put in the folder with the demo page.
<?xml version="1.0"?>
<configuration>
<configSections>
<!--You need this part so that you can have a neatupload configuration section. You will get .net errors if you try to add the configuration section without this part here.-->
<section name="neatUpload"
type="Brettle.Web.NeatUpload.ConfigSectionHandler, Brettle.Web.NeatUpload"
allowLocation="true"
/>
</configSections>
<!--This is where you put your neatupload configuration preferences.-->
<neatUpload xmlns="http://www.brettle.com/neatupload/config/2008"
useHttpModule="true"
/>
<system.web>
<customErrors mode="Off"/>
<!-- Always required to use any of NeatUpload's features. Without it, ProgressBars won't display and MultiFile will look like a regular HtmlInputFile. -->
<httpModules>
<add name="UploadHttpModule" type="Brettle.Web.NeatUpload.UploadHttpModule,Brettle.Web.NeatUpload,Version=1.3.3798.663,Culture=neutral,PublicKeyToken=c95290d92c5893c8" />
</httpModules>
<!-- Set these next 2 attributes large enough to accomodate the largest and longest running upload you want to support. Note that browsers and IIS typically don't support uploads larger than 2GB (2097151 KB). -->
<httpRuntime maxRequestLength="2097151" executionTimeout="999999"/>
<!-- Not required for NeatUpload but makes it easier to debug in VS. -->
<compilation debug="true"/>
</system.web>
<!-- For IIS7's Integrated Pipeline Mode which is used by the DefaultAppPool. -->
<system.webServer>
<security>
<requestFiltering>
<!-- Increased maxAllowedContentLength from default of 300MB. -->
<requestLimits maxAllowedContentLength="2147483648" />
</requestFiltering>
</security>
<modules>
<add name="UploadHttpModule" type="Brettle.Web.NeatUpload.UploadHttpModule,Brettle.Web.NeatUpload,Version=1.3.3798.663,Culture=neutral,PublicKeyToken=c95290d92c5893c8" preCondition="managedHandler"/>
</modules>
<validation validateIntegratedModeConfiguration="false"/>
</system.webServer>
</configuration>
Some Notes on Installation Packages
The installation package I used was at http://neatupload.codeplex.com/releases/view/46086 - there seem to be a few others, such as a "binaries package" at http://neatupload.codeplex.com/releases/view/59339, but the directory structure is different, and the instructions won't make much sense. There is also a package on the main project page at CodePlex: http://neatupload.codeplex.com/, but if you use this package, you will have a different version number and guid for the dll when you deploy it to the GAC.
Instruction Manuals
By way of an instruction manual, check out: http://mumblestiltskin.blogspot.com/2009/10/using-neatupload-simple-setup.html?showComment=1335835416022#c1846924755786832325, and there is also an html manual in the binaries package above. In the other packages, you have to "build" the manual with Open Office. Then, of course, you can reference this post!
Troubleshooting
Having problems?
How to Overcome this NeatUpload Object Reference Error?
NeatUpload Nabble Forum: http://neatupload-help.688956.n3.nabble.com/
The only thing left now, is to add some sort of handler for copying the files to where you want them. NeatUpload only adds them to a temp file, and I have yet to figure out where it is...