How to publish a file only once? ASP.NET vNext - c#

I have a config file which contains version of some client. I need publish this file only once, and it should be same after every publish of web app. How can I do it?
I use Visual Studio Online for continuous deployment and after every push web app in the qa server is updated.

You can use Web Deploy to publish your web app.
By default, Web Deploy determines which files need to be copied to the
server by comparing the dates that the local files were last changed
against the dates that the server files were last changed. If you use
a source control system that changes file dates when you check out
files, it appears that they have all changed, and Web Deploy copies
them all to the server when you publish.
An alternative for this scenario is to configure Web Deploy to use
file checksums to determine which files have changed. Use checksums
only if file dates are unreliable indicators of what has changed,
because comparing checksums takes more CPU processing time than
comparing dates.
Or:
You can limit the files that are deployed by selecting the Only files
needed to run this application or All files in this project options on
the Package/Publish Web tab. If you select the All files in this
project option, you can right-click a file in Solution Explorer and
select Exclude From Project to keep it from being deployed. For more
information about what files are excluded when you use the Only files
needed to run this application or All files in this project options,
see Why don't all of the files in my project folder get deployed?.
If these options are not flexible enough for you, another option is to
edit the .pubxml or the .wpp.targets file and add an
ExcludeFilesFromDeployment element or an ExcludeFoldersFromDeployment
element (or both) in the PropertyGroup element. In each element, you
can specify a single name, or you can specify multiple names delimited
by semicolons (;), as shown in the following example:

Related

How do I determine the web origin folder of a ClickOnce application?

I have an C# application that is deployed as a ClickOnce application. The installation files can live in one of three possible folders on our web server: Alpha, Beta, and Production. The user addresses the appropriate location in IE to start the application: www.foo.com/Alpha, www.foo.com/Beta, or www.foo.com/Prod. In testing, we copy the installation files to Alpha first, then (when it passes testing) to Beta, then (when it passes user acceptance), to production. There is no recompilation.
What I want to know is whether there is any way the C# code can know at runtime which version it is: Alpha, Beta, or Production. It would be based only on which folder the ClickOnce installation files were located in. Remember that there has been no recompilation.
Any clues?
Thanks!
You could do this with a custom manifest element, but it will require some post-build processing.
The application can access the manifest file simply by opening a file stream on the AppName.exe.manifest file, and parsing the XML to locate and read the custom element. The manifest is deployed to the same directory as the executable.
When the application files are copied to a web server folder, simply modify the manifest to append the custom element (it could technically even be an XML comment, parsed with simple text comparison, if you don't want to use an XML parser).
After the manifest is modified (in each folder), it will have to be re-signed with the mage.exe signing tool.
You can automate this with a shell script fairly easily. On the whole, however, it would probably be a lot simpler to just build different actual versions.

How to create folder in mvc solution directory so that it is included in project?

I am new in mvc and c# and I can't solve following problem:
I am trying to create a folder named "Items" in solution folder.
I have tryed to use CreateDirectory method:
Directory.CreateDirectory("~/Images");
But it didn't work for me - folder wasn't created ..
Partly working solution was to create a folder by :
Directory.CreateDirectory(Server.MapPath("~/Images"));
"Items" folder was created, but it is not included in the solution:
How to create folder in solution directory so that it is included in project ?
(I needs to by done by code not by hand)
You need to understand what solution and csproj file is used for
In general, they're being designed and used for development with Visual Studio, and once the project is compiled, all these files will be ignored and excluded from the deployment package
Directory.CreateDirectory(Server.MapPath("~/Images"));
The code above simply create the directory if not existed yet in the deployment package at run-time, so you won't see it in your solution unless you run the project locally (either debug/release mode, it does not matter here). However, everything will run normally in hosted environment (ex: IIS).
For your information, here's the brief of what solution and csproj is
solution (.sln) file: contains information to manage one or many individual projects, contains build environments (for each project), start up mode (useful when you want to start multiple projects in one run), project dependencies and so on. Take a note that VS also read from suo file (solution user options) which is used to defined user-custom preferences (you should not include the .suo file in the version control, because it's custom settings)
csproj file: define the structures of project, what the namespace is, what is static folders, embedded resources, references, packages, etc.
Lastly, if you create the folder manually, VS will auto include that folder into deployment package AND csproj, but depends on the file type, you might need to change the Build Action and Copy To Output Directory in file properties.
Hope it helps.
A deployed web application on a web server doesn't have any notion of Visual Studio solution or projects. So the Directory.CreateDirectory(Server.MapPath("~/Images")) is the correct way to create a folder inside your web application at runtime but we cannot be talking about including it into a solution because this hardly makes sense in a pre-compiled web application. If you create the directory on your local development machine, you could always manually include the folder to the corresponding .csproj file, but at runtime this will not make any difference whatsoever.
The reason I wanted to create a folder (if didn't exist) was to make sure it exits before I try to store image in it.
After reading posts here and a few google searches I have concluded that the proper way to handle image upload would be
To create (In my case) folder "Images" by hand to be sure it exists
Then storing uploaded img in existing folder:
string path =Server.MapPath("~/Images/"+ UploadedImageName);
file.SaveAs(path);

Include config file after publish with WiX

Scenario:
I have two applications, a Windows Forms App and a Windows Service App. The two applications work together, use same libralies (dll) and share the same configuration file (this file is not the app.config but a custom file).
Complications:
I have a website (webforms) where the user will enter information about configuring the software, this information will be saved in the database and from this information will be generated the configuration file. The site should generate build the project with the new configuration file and the page responds to the client's request with a link to download the .msi.
Problem:
How to generate an installer from a command line to be called by the web application after generating the configuration file. I researched and found the Windows Installer XML (Wix), but it seems to be necessary to compile the entire project every time someone downloads. It's possible leave the program compiled and only add the configuration file after?
Apretiate any helps
Light (the linker in the WiX Toolset) has a feature called "cab cache" which will re-use the cabinet files which are embedded in the resultant MSI. You would use the arguments -reusecab and -cc to enable this.
You'll still have to re-build the MSI when the user submits your form, but the build will be faster (cabinet generation is usually the longest part of the build process).

Deploy different WCF .svc files based on configuration

I have a Service1.svc file that is a normal WCF service. If I deploy the WCF project it will happily copy the Service1.svc file along with the binaries and the other files. So far, so good. What I want is, based on the selected build configuration, or some other trick, to publish different contents for the Service1.svc file.
Let's say I have a Service1.Conf1.svc file and a Service1.Conf2.svc file and two configurations (like Debug or Release) that are named Conf1 and Conf2. When I click publish and have the Conf1 configuration selected, I want the publish folder to have a virtually created Service1.svc file whose contents are from Service1.Conf1.svc. When I click publish and have the Conf2 configuration selected, I want the publish folder to have a virtually created Service1.svc file whose contents are from Service1.Conf2.svc.
I would like to have this for the publish action, not the build action (which could be achievable by a post-build or pre-build event). The main purpose is to adjust the contents of the Service1.svc file according to the publish environment.
Any ideas?
We took a different approach and generate all required config/svc files for all possible installs (using TT file generation) and let the installer copy the correct configs/svc files (based on user selection during install).
The names of the files are constructed by inserting the target platform name into the standard name e.g web.local.config, web.dev.config, web.test.config etc
This way you can give one installer to anyone from any department. They just choose the platform.

How to add external file outside the application folder to clickonce deployment (winappliction.net) [duplicate]

I've got an application that I'm moving over to ClickOnce and the app has a moderately sized data folder with hundreds of files that I need to inlcude in the deployment. The folder needs to be in the same place relative to the EXE after deployment. I've seen several suggestions on how to do this but there doesn't seem to be a agreed upon method for doing this.
Any suggestions would be great -
Thanks!
One good way of doing this is:
Create a folder under the app in VS name e.g. "datafiles"
Add all files to that folder using Add as link in the dialog box after selecting Add existing item on the folder
Mark all files as Copy if newer (Copy to output directory property)
Make sure the build action is content
--> when you publish the files will be put in that folder and be a part of the application installation
Good luck!
After deployment, all files marked as data are placed in the ApplicationDeployment.DataDirectory folder. I know of no way to change this. You could copy the data files during the first run of your app, but this approach will not survive any upgrades that include data file changes.
Alternatively if you have control over the location of the data folder during development, you can place in the same relative (to the app folder) location as will be specified after deployment.
https://msdn.microsoft.com/en-us/library/kzy0fky2.aspx
https://msdn.microsoft.com/en-us/library/6fehc36e.aspx
These two articles provide methods of doing this. Between the two of thing you can find one that works for you. The one that worked for me was:
With a project selected in Solution Explorer, on the Project menu,
click Properties. Click the Publish tab. Click the Application Files
button to open the Application Files dialog box. In the Application
Files dialog box, select the file that you wish to mark as data. In
the Publish Status field, select Data File from the drop-down list.

Categories

Resources