I am trying to create a new web application using OS X and VS Code from scratch without using any scaffolding tool. My starting point is Scott Allen's tutorial on pluralsight:
https://app.pluralsight.com/library/courses/aspdotnet-core-1-0-fundamentals/table-of-contents
My project structure is:
The global.json file contains
{
"projects": [ "src" ],
"sdk": {
"version": "1.0.0-rc1-update2"
}
}
And the project.json currently contains
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": false
},
"dependencies": {
"Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
"Microsoft.AspNet.Hosting": "1.0.0-rc1-final"
},
"frameworks": {
"dnx451": {},
"dnxcore50": {}
},
"commands": {
"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://localhost:5000"
},
"exclude": [
"wwwroot",
"node_modules"
]
}
I have run dnu restore to get the packages and now I would like to run the web. I need to go to the web app folder and run dnx web in order to do so and the app starts
Is it possible to run the application directly from the root folder, not from the web app folder? Is the global.json file needed in such setup? And how do I change the hosting environment? I have gone through the documentation, but the hosting environment is only clear when using VS 2015.
You cannot simply run from the root because there could be multiple projects that are "executable". But you can pass the project to dnx using the --project/-p argument.
The environment is set using the ASPNET_ENVIRONMENT environment variable.
The global.json file is useful for two things:
The sdk section is only by VS.
The projects section is used all the time and it's useful if you have the projects in multiple folders (for example src and test). If everything is in a single folder, you don't need it.
So, the bare minimum in order to run an web application is:
A folder for your project
A project.json file
A startup file
Related
I have a project which uses dependency having having version same as that of the project. So I would like to change the version only in one place and write something like below this in my package.json
{
"name": "my-child-app",
"version": "1.2.3",
"description": "My Application",
"dependencies": {
"my-parent-app": %npm_package_version%
}
}
Basically the child app is always supposed to have version in sync with the parent app. So any approach where I will have to change only one line (instead of two in usual scenario) when I have to upgrade to a newer parent-app would suffice.
Note: I am using frontend-maven-plugin to build the project as child-app is a module of Java Project. parent-app is also built in a same way but they are not in the same code repository so file referencing cannot be used.
I am using
TeamCity Enterprise 2017.1.2 (build 46812)
Artifactory Professional 5.3.1 rev 50046
Teamcity has the Artifactory plug-in installed (ver 2.3.0)
The task is simple - download files from Artifactory to Teamcity build:
From Artifactory MyRepo/RootFolder/ProjectFolder/1.2.3/<files>
To TC %checkoutdir%/artifacts/<files>
The <files> part of the path contains both folders and files and I want to retain their structure.
The download spec json is:
{
"files": [
{
"pattern": "MyRepo/RootFolder/ProjectFolder/1.2.3/",
"target": "artifacts/"
}
]
}
However, the files get downloaded into a different location than I would expect:
Actual: artifacts/RootFolder/ProjectFolder/1.2.3/<files>
Expected: artifacts/<files>
The whole path from Artifactory gets appended after the target directory. How do I tell the plugin to only use the relative path of files after the specified root? I have tried fiddling about with wildcards, slashes etc, but nothing helped.
I had to create an extra build step where I manually move files to the structure I expect, but I would prefer not to have to do that.
WORKING ANSWER:
{
"files": [
{
"pattern": "MyRepo/RootFolder/ProjectFolder/1.2.3/(*)",
"target": "artifacts/{1}",
"flat": "true"
}
]
}
You can customize your target structure by using Placeholders in your File Specs as described here.
Placeholders allow you to capture a specific section of your File Spec "pattern" property value, and use it inside the "target" property value.
In your case, the download File Spec should look like this:
{
"files": [
{
"pattern": "MyRepo/RootFolder/ProjectFolder/1.2.3/(*)",
"target": "artifacts/{1}"
}
]
}
I want to learn fsharp. So I'm looking at exercism.io
In their readme they instruct to use Xamarin Studio for running the test
http://exercism.io/languages/fsharp/tests
But I would like to just run the tests from the terminal. The exercises from exercism only include one F# file e.g. HelloWorldTest.fs.
This answer Running tests on Mac OS X console using mono/nunit-console/4 instructs to run nunit-console with a .csproj or .dll file. But these files are not present in the exercism files. So I'm not clear what to do.
I have install mono using homebrew.
How do I run the NUnit test from the terminal in OSX?
You may have to use xbuild on the command line to compile the fsproj file then the resulting dll can be executed with nunit on the commandline also.
If you don't have the fsproj you can use fsharpc on the file directly then call nunit, remembering to use mono to execute nunit.
fsharpc HelloWorldTest.fs
mono nunit-console.exe HelloWorldTest.exe
Sorry am not in a position to test this, but should be something like this.
I figured out how to do this:
1. install dotnet as described https://www.microsoft.com/net/core#macos
2. In the folder of the exercise run
dotnet new --lang f#
3. Rename Program.fs to the name of the exercise e.g. HelloWorld.fs
4. Change project.json to
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true,
"compilerName": "fsc",
"compile": {
"includeFiles": [
"HelloWorld.fs",
"HelloWorldTest.fs"
]
}
},
"dependencies": {
"NUnit": "3.4.1",
"dotnet-test-nunit": "3.4.0-beta-2"
},
"tools": {
"dotnet-compile-fsc": "1.0.0-preview2-*"
},
"frameworks": {
"netcoreapp1.0": {
"imports": "portable-net45+win8",
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
},
"Microsoft.FSharp.Core.netcore": "1.0.0-alpha-160629"
}
}
},
"testRunner": "nunit"
}
This includes the nunit dependency.
Note includeFiles, this should include the source code file for the exercise and the test file. e.g. HelloWorld.fs and HelloWorldTest.fs
5. Install required packages by doing
dotnet restore
6. Add your code to the previously renamed source file e.g. HelloWorld.fs
7. Finallly, run test by doing
dotnet test
I found this (seemingly) related SO post, but following the suggestions from both answers didn't help, all my js files are getting pushed to Azure (not just the *.min.js files from my js folder.)
What am I doing wrong? Is this possible? I could update my gulp script I suppose to read an environment variable ("Development", or "Production") and then delete the source js files conditionally. It just seems to be better to make the build task function as I wish (especially since it looks doable.)
Js files for my project are in [solution folder][project folder]\wwwroot\js.
According to the comment you added in the related SO post you mentioned, I assumed that your application is Based on ASP.NET Core. As far as I know, we could determine that which file/folder could be included or excluded when publishing your web application by configuring the publishOptions section in your project.json file as follows:
"publishOptions": {
"include": [
"wwwroot",
"wwwroot/js/**/*.min.js",
"Views",
"Areas/**/Views",
"appsettings.json",
"web.config"
],
"exclude": [
"wwwroot/js/**/*.js"
]
}
But, as this tutorial mentioned that the exclude patterns have higher priority than the include patterns, hence a file found in both will be excluded. In this situation, you need to configure all the included/excluded files in the includeFiles/excludeFiles node of the publishOptions.
According to your requirement, Using Gulp would be an ideal approach to achieve it.
Additionally, if your project is an ASP.NET MVC application, you could add the following to your .pubxml file.
<ItemGroup>
<ExcludeFromPackageFiles Include="wwwroot\js\**\*.js" Exclude="wwwroot\js\**\*.min.js">
<FromTarget>Project</FromTarget>
</ExcludeFromPackageFiles>
</ItemGroup>
I ended up going the gulp route thus far (still interested in the other alternatives if viable.)
Created a new task in my gulpfile...
var del = require("del");
gulp.task("remove-non-minjs", function () {
return del([
paths.scripts.dest + "**/*.js",
"!" + paths.scripts.dest + "**/*.min.js"
]);
});
And then added this to my project.json's prepublish script...
"scripts": {
"prebuild": [ "gulp default" ],
"prepublish": [ "npm install", "gulp default", "gulp remove-non-minjs" ],
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
I verified it works, but just seems a bit hacky.
This seemed to do the trick for me:
https://learn.microsoft.com/en-us/aspnet/web-forms/overview/deployment/advanced-enterprise-web-deployment/excluding-files-and-folders-from-deployment
Via the Solution Explorer, you can edit the Properties of each file in your project and set the Build Action to NONE. It looks like you might be able to select multiple files at one time while doing this.
I'm upgrading from asp.net mvc 4, asp.net webforms, Ef 5 and MEF 1 to dotnet core.
despite existing code, that they decided to not support in dotnet core and i need to read many places to found what is going on dotnet corefx development, one of my big problems is that i don't understand vs 2015's system of adding dependency and etc.
i'm going to use MEF2(System.Composition), simply because it seems the MEF1(System.ComponentModel.Composition) is not going to be implemented in dotnet core. so i created a project of class library(package) in vs2015 as follow:
and then typed :
Install-Package Microsoft.Composition
into PM.
now, my project.json file looks like this:
{
"version": "1.0.0-*",
"description": "___ Class Library",
"authors": [ "___" ],
"tags": [ "" ],
"frameworks": {
"net451": {
"dependencies": {
"Microsoft.Composition": "1.0.30"
}
},
"dotnet5.4": {
"dependencies": {
"Microsoft.CSharp": "4.0.1-beta-23516",
"System.Collections": "4.0.11-beta-23516",
"System.Linq": "4.0.1-beta-23516",
"System.Runtime": "4.0.21-beta-23516",
"System.Threading": "4.0.11-beta-23516"
}
}
}
}
the problem is that : is this a dnx project that only used dnx packages? and yes, the project's file extension is .xproj.
to me it seems that i'm using full .net framework 4.5.1 implementation of MEF2.
also here is a link Using System.Composition in dotnet corefx page that i don't found any useful info on it.
is this means that they dont implemented the MEF2 in dotnet corefx yet?
Replace "dotnet5.4" for "dnxcore50". Yes, MEF 1 won't be supported, only MEF 2.
I wrote a post about using it, which you can find here: https://weblogs.asp.net/ricardoperes/using-mef-in-net-core.