I would like to add a console app as a reference to an asp.net project. Ideally I want them in the /bin folder (or in a sub folder in the web/output folder). Unfortunately, adding the console app as a reference will put the build output in /bin of the web project, but it will not generate the App.config file.
Does anyone know the proper way to include a console app in the build/publish process of an asp.net project?
Thank you,
Adding it as a reference will affect compilation, which is not what you want.
Instead, you should add a build step (to either project) to copy the EXE & config file to a directory of your choice.
You should also edit the solution to add the EXE as a dependency of the web project to make sure it builds first.
Related
We have an ASP NET Core 6 API application hosted on Azure App Service.
Together with the application we would like to deploy some external xml files that are used later on by the backend runtime. We have added them to the project and set CopyToOutputDirectory = true.
Have to questions:
How to access these files from code in safe way?
What we tried is
Assembly.GetExecutingAssembly().GetName().CodeBase)?.Substring(6) to get base path but it looks hacky.
_webHostingEnvironment.ContentRootPath but it returns wrong location in development (project root folder instead of /bin)
using relative path Path.GetFullName("file.xml") but it returns project root folder in development as well
We saw that there is another property that can be set on file called CopyToPublishDirectory. When it should be set? We set only CopyToOutputDirectory and it seems to work also when doing dotnet publish. Any reference?
Let's approach this problem in a different way. When we publish the project, we include the bin folder in the publish file. Then you can access .xml inside the bin folder.
Show all files and include to your project.
Open .csproj file and modify it.
And your csproj file should be like:
https://dotnetfiddle.net/qG3W8h
comment out this paragraph and add CopyToOutputDirectory, like below:
https://dotnetfiddle.net/jrccnJ
Then you can deploy it, then you can find the bin folder.
Then you can access the file gracefully.
I have this solution structure:
AppOne.Account
AppOne.Admin
AppOne.System
AppOne.Data
AppOne.ClassLibrary
AppOne.Account, AppOne.Admin and AppOne.System are ASP.NET Core Application Projects. The rest are libraries.
Currently I have to manually copy and paste the same web.config file to each of them when I deploy and even in development, I have to copy and paste the launchSettings.json file as it contains their environment variables that I need.
Is it possible to store the web.config or launchSettings.json file in a folder and then reference it in my Startup.cs.
I am thinking of storing it in a Solution folder and then reading the in. However, I am unsure if that is possible and I am also unsure of where to read it from.
You don't "reference" the web.config. You put the app/web.config file in the project (or a short cut to the single Config file that actually lives in another folder).
Then in code you use ConfigurationManager.AppSetting... and that will look for the config file in the running project. It's context based.
If you are running the main project it'll look at the main project for the config, if you're running a Unit Test project then it'll expect a config file (or a shortcut) lives in the root of the unit testing project.
A nifty solution is adding config file shortcuts in other projects so you only update one file:
I'm working with Visual Studio. There I have a solution with several web-projects (.net MVC 4). All of these web-projects use the same javascript-libs. Currently I copied the library into each project, but this can't be the final solution. What is the best approach to share those library (assets in general) between all of the projects? Just link them? Or is it possible to create a project and reference it in all projects?
Update
"Link" the javascript files from another project is not a possible solution as I would have to link thousands of files (one of the libraries I am using is ExtJs) what makes it impossible to build a project without freezing visual studio...
Possible solution
Currently I have a (Web) MVC Project called "Web" and a (Class Library) Project called "ClientScript" which contains all the JavaScript files which are shared between several Web Projects. As linking all the needed JavaScript files is not a possible solution (because it's a matter of thousands of files what causes visual studio to freeze) I copy all the needed JavaScript files to the individual Projects using the Build Events in each Web Project (Project -> Properties -> Build Events -> Post-build).
My Post-build command line in the Web Project looks like this:
start xcopy "$(SolutionDir)ClientScript\Frontend\*" "$(SolutionDir)Web\Scripts" /r /s /i /y /D /E
Every time you build your Web Project all the changed Javascript files get copied from the ClientScript Project to your Web Project.
While developing the Javascripts I run a small "filewatcher" tool which automatically copies a file from the ClientScript Project to every Web Project when it changes. This way I don't have to build the Web Project every time when I make a change to one of the Javascripts.
Anyone that stumbles across this question here in the future should know that there are now Shared Projects in Visual Studio to solve this problem. Universal Windows projects use them by default and you can create your own by downloading and installing the VS extension here: https://visualstudiogallery.msdn.microsoft.com/315c13a7-2787-4f57-bdf7-adae6ed54450
Note: At this time they can be picky about what type of project you try to add the shared reference. I created a JavaScript shared project to share js files between a Windows store js app and an MVC web app and it would not let me do that saying they had to be of the same language. (It supports C#, C++, or JavaScript).
Place the JS files in a single folder, likely above all others, and add them to the project but use the "Link" option. It's part of the drop down on the "OK" button in the "Add existing item..." dialog.
When you run every new ASP.NET MVC 4 project it's take a new port then other app have take.
I simply suggest you a simple thing.
run a project which contain all the pacakages. open them webmatrix and run them as localhost:80.
You need to set the port in settings section of your site in webmatrix. Now it will rechable at localhost now you can reference all the libraries from this packages.
Slightly older thread, but I have another way of doing a similar thing using Web Essentials, that handles the issue of not publishing correctly.
I have a shared folder outside of the projects that require the shared file, normally a 'common' project with other things in as well, but can be just a simple folder as suggested by Michael Perrenoud.
However instead of 'Add as Link' I have been creating a new bundle in the project that requires the shared js/css file, with the same name as the shared file, and then referencing that file in the shared folder using a relative reference location rather than the root based one it starts with.
To add a file from a shared folder in the root of the solution to the scripts folder use the following code in a new bundle file (*.bundle), changing the folder/file names as required.
<?xml version="1.0" encoding="utf-8"?>
<bundle xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://vswebessentials.com/schemas/v1/bundle.xsd">
<settings>
<minify>false</minify>
<runOnBuild>true</runOnBuild>
</settings>
<files>
<file>../../MySharedFolder/my-js-file.js</file>
</files>
</bundle>
Then every time you build it recreates the bundle with the latest version, this version is then also published as expected :)
You can even create a minified version if desired by changing 'minify' to true. Or better yet you can add them loads as a bundle too if you want, you have that flexibilty.
This is an older thread but due to complex business requirements these days applications are divided in to different modules or sub projects.Thus, brings us the need to share common resources like JavaScript files, themes and CSS style sheet files.
I personally feel that common files should be put in separate Asp .Net MVC 5 project which has following structure :ASP.NET MVC5 folder structure
Now the best part is you can separately manage the dependencies using Bower,NPM or Nuget package manager.
After you have organised all the files in this project host this project to your own CDN or may be on cloud. You can use Using CDN in Bundle Approach to get script or link references.
That will help you sharing common resources across all the projects.There us a short coming though if you have many developers on the team and if someone added incompatible version lib can affect all the apps.
I have a Visual Studio 2008 solution with an ASP.NET Web Application project. I want to change the default output folder, of said project, to $(SolutionDir)\WebApps\$(ProjectName)\bin. This I can do and when I build I get the expected assembly files in this folder. It doesn't copy the content files (aspx, etc.) to the parent folder but I have managed to fix this by hacking the project.csproj file with a custom build target.
The problem is I want to be able to debug this application using the ASP.NET Development Server, by pressing F5 in VS2008. Unfortunately the ASP.NET Dev server starts, has a "Physical Path", in the project directory rather than the parent of the output directory.
Is there any way to build my web application to a different output folder but still run the asp.net dev server to debug my site?
Thanks.
Short answer is yes, but it isn't pretty. The process I used is given below.
Unloaded the project in VS.
Manually edited the .csproj file to include a post build action that basically copies the content files (aspx, etc.) to the parent of the output folder.
For the debug options I set the project to launch an external executable. The Asp.Net Development server. Also manually set the url to launch.
What I learnt? I wouldn't do this, I'd just stick with the default and create an install/web deployment project instead.
Where can I find the application.exe.config file in my C# project?
I'm attempting to enable the JIT debugger but cannot find the config file.
thanks!
It's usually in the root of your project. If its not there you might not have one. You can add it by right clicking on your project and add new item.
It's called App.Config at this point. Once you compile it is then renamed to AppName.exe.Config, and placed with your build output.
I had to learn that each project in the solution can have a settings file. But the one in the startup project is the one that becomes application.exe.config in your output folder.
It should be in \bin\Debug or \bin\Release, right next to your compiled assembly.
It will be app.config . App.exe.config will be created in case of windows app,test project or asp project or any other projec which shows output