Cannot find content file in bin folder - visual-studio

I have a IIS Express project running in debug mode in Visual Studio 2015.
The web application references a Class Library which has this line of code:
var certificate = new X509Certificate2(#"certkey.p12", "notasecret", X509KeyStorageFlags.Exportable);
The certkey.p12 file is in the same folder as the source code for the class library as is marked as "Build Action = Content" and "Copy if newer".
When I build, the file is copied to the web app's bin folder as expected. But when I call the method from the web app, it throws "file not found".
It works fine in Unit Testing where the file is copied to /bin/x64/Debug/
So where is IIS Express looking for the file? I suspect it is some sort of temp folder but why isn't VS copying the file there when I build/debug?

When running under IIS Express, it was looking for is "C:\Programs Files\IIS Express\certkey.p12".
I used a little peeking to find the folder that the file was actually copied to and came up with this:
string binPath = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
Uri uri = new Uri(binPath);
string localPath = uri.LocalPath;
string dir = System.IO.Path.GetDirectoryName(localPath);
// now "dir" is the full local path of the bin folder
It is a little slow on first execute (~100ms) but faster on subsequent requests.
If there are any problems when I deploy this to production, I'll update.

Related

Code a File Path that works in both OSX and Windows (dotnet core)

I have to save files in my dotnet core application. I originally developed in windows; but when I ported the code to try developing on a mac, the file path is no longer valid (i.e. "c:\content..."). Is there a way to reference a file path, in my code, that will work in both situations? We deploy to azure... so the windows file path must there too.
FileInfo fileInfo = new FileInfo("c:\\Content\\SalesOrderOutput\\" +
fileName.txt);
FileStream stream = fileInfo.OpenWrite();
Use Path.Combine method like this:
internal static readonly FileInfo Mp4WithAudio = new FileInfo(Path.Combine(Environment.CurrentDirectory, "Resources", "input.mp4"));
Code from https://github.com/tomaszzmuda/Xabe.FFmpeg/blob/c8cc4232b5afa2860ede3be63a680d754ed73002/Xabe.FFmpeg.Test/Resources.cs

Having Issues With EV Code Signing

I have recently purchased EV Code signing certificate from DigiCert...
Now i am having issues to sign my installer executable files.
Currently (Till now) below is the process to make the installer:
Step-1:
My installer is configured in a way so, it will load all common files from it's child support directory.
like below files structure:
Setup.exe (it's only have application exe file and few other configuration file that changes time to time)
Support (Directory)
Support\DLL (Has DLL files that is required by my application)
Support\Others (Any Other files)
Support\ETC (Just for example purpose)
All those support files is resided on my server as they don't change frequently
so, i have created a wrapper installer.exe file and a script to handle the wrapper..
That wrapper installer.exe file also resides on my server
Step-2:
My script does below steps:
a) make the setup.exe with the updated application files.
b) upload setup.exe file to server
c) add (append) that setup.exe and all others required files at the end of wrapper installer.exe file
d) I Provide That wrapper installer.exe (single file) to my clients/users.
Step-3:
When that wrapper executes, it creates a temp folder in temp directory. extract all the files that is appended in itself. and run the setup.exe from that temp directory
I make this process, as i only have to change application file that is few kilobytes only (always below 1mb), but those support files are huge in size.
So, instead of having to upload all those files from my local computer each time.
i make this wrapper process to make update/upload process much faster.
Now, The Problem:
If i sign the wrapper.exe file and put it to server, but when my script append data to that file, it looses the certificate settings (it's no longer signed :( )
so, how can i overcome this situation..
Update-1:
As asked, below is the php code that used to append setup.exe file:
//Appending Setup.exe file...
$archive_File = 'files/' . $strFileID . '.exe';
if (is_file($archive_File) == 1)
{
$strSize = filesize($archive_File);
$strData = 'Setup.exe' . chr(0) . $strSize . chr(0) . file_get_contents($archive_File) ;
file_put_contents($strArchiveFile, $strData, FILE_APPEND | LOCK_EX);
}
else
{
exit ('following file does not exits: ' . $archive_File);
}
best regards
You can't modify wrapper.exe after you've code signed it. That's the whole point of code-signing - to validate that a virus or other tampering didn't occur on the signed executable.
I'm not sure why you are code signing wrapper.exe first, then appending the files to it afterwards. You need to do the following steps:
Code sign setup.exe and all other binaries first except for wrapper.exe
Append setup.exe and all other files to wrapper.exe.
Then code-sign wrapper.exe after it's been fully built.
There are a lot of free tools that will generate a self-extracting archive that when run will prompt the user to run the setup.exe within it. 7Zip will do this for free.
But it sounds like you need to build your wrapper.exe on demand right before it's downloaded. If that's the case, add the code signing script to your server code that builds the final wrapper.exe

accessing App.Config file after deploy in C#

Im using below code to update app.config's some values( I have config file path in the app.config file).When deploy its getting errors I think its becouse app.config file change in to an exe. how to change my code work as debug time as well as deploy time
var appPath = ConfigurationManager.AppSettings["configPath"].ToString();
string configFile = System.IO.Path.Combine(appPath, "App.config");
var configFileMap = new ExeConfigurationFileMap();
configFileMap.ExeConfigFilename = configFile;
System.Configuration.Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);
config.AppSettings.Settings["InvoiceInterval"].Value = InvoiceIntervalVal.ToString();
Hi thanks every body for instance reply. I fix my own problem it was just a confusion. I was a java guy and I new to .net in .net App.config file compile and create .config in Debug folder file even though debug it access that .config file in Debug folder . So actually when if you change the value in App.config in programatically it doesn't change the App.config file. it change the .config which is in debug file.its like [project name].vshost.exe.config in debug folder.
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["InvoiceInterval"].Value = InvoiceIntervalVal.ToString();
config.AppSettings.Settings["directPaymentInterval"].Value = directPaymentIntervalVal.ToString();
config.AppSettings.Settings["paymentStatusInterval"].Value = paymentStatusIntervalVal.ToString();
config.Save();
ConfigurationManager.RefreshSection("appSettings");
using above code you can able change App.config file's value in debug time also in run time. but those changes not seems in App.config file. but you can see changes in exe file which it is belongs to.In my case it was in src\Vetserve.Credicare\bin\Debug\Vetserve.Credicare.vshost.exe.config
Perhaps try and set your App.config's file 'Copy to Output Directory' property to 'Copy always'.
Reference: AppConfig file not found in bin directory
After compilation App.Config will be available as
YourConsoleApplication.exe.Config inside application bin.
You can do like:
var beforeInvoiceInterval = ConfigurationManager.AppSettings
["InvoiceInterval"].ToString();
ConfigurationManager.AppSettings["InvoiceInterval"] = "Your value";
var afterInvoiceInterval = ConfigurationManager.AppSettings
["InvoiceInterval"].ToString();
afterInvoiceInterval will contain the value you assigned but it'll not
modify YourConsoleApplication.exe.Config.

Specify VS extension installation directory name

After installing extension in VS 2012 it is placed in %userprofile%AppData\Local\Microsoft\VisualStudio\11.0\Extensions\ (or in C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\Extensions if it is installed for all users) and in folder with random name like "hilatg23.234" or "kcsuvnvi.qtq". Is there a way to specify the name of this folder and make this extension to install to folder like %userprofile%AppData\Local\Microsoft\VisualStudio\11.0\Extensions\MY_EXTENSION_NAME
Hm, don´t think so. The VSIX installer will always choose the installation directory automatically. If you want to let the user decide about the installation folder, you´d need to create a MSI installation package.
A while ago I answered another question regards the package registration; maybe some of the provided information might help to create such a setup. See post at: MSI installed VSPackage is loaded in Experimental Instance only
If you just want to obtain the package installation folder at runtime, you can just get it from the package´s assembly codebase, like:
private static string ObtainInstallationFolder()
{
Type packageType = typeof(MyPackage);
Uri uri = new Uri(packageType.Assembly.CodeBase);
var assemblyFileInfo = new FileInfo(uri.LocalPath);
return assemblyFileInfo.Directory.FullName;
}
My solution:
I use this api get vsix install physical path:
string path = System.Reflection.Assembly.GetExecutingAssembly().Location;
path = \AppData\Local\Microsoft\VisualStudio\...\Extensions\[install path]\xx.dll
You can control the name of the Extensions<folder> with this msbuild property in your vsix project file:
<ExtensionInstallationFolder>YourExtensionName</ExtensionInstallationFolder>

.net 3.5 SP1 Bootstrapper not found for Setup

I am getting a warning when trying to include the .net 3.5 sp1 prerequisite for my setup project. The warning states Prerequisite could not found for bootstrapping.
Any suggestions?
Thanks
I followed the directions in 2.3.1.1 Enable Samesite for the .NET Framework 3.5 SP1 bootstrapper package and now everything works perfect.
Thanks
Ultimately, having had the same issue as the creator Ryan, I solved my delima by folling these steps:
Update the Package Data
Open the [Program Files]\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages\DotNetFx35SP1 folder or %ProgramFiles(x86)%\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages\DotNetFx35SP1 on x64 operating systems
Edit the Product.xml file in Notepad.
Paste the following into the < PackageFiles > element:
<PackageFile Name="TOOLS\clwireg.exe"/>
<PackageFile Name="TOOLS\clwireg_x64.exe"/>
<PackageFile Name="TOOLS\clwireg_ia64.exe"/>
Find the element for < PackageFile Name="dotNetFX30\XPSEPSC-x86-en-US.exe" and change the PublicKey value to: 3082010A0282010100A2DB0A8DCFC2C1499BCDAA3A34AD23596BDB6CBE2122B794C8EAAEBFC6D526C232118BBCDA5D2CFB36561E152BAE8F0DDD14A36E284C7F163F41AC8D40B146880DD98194AD9706D05744765CEAF1FC0EE27F74A333CB74E5EFE361A17E03B745FFD53E12D5B0CA5E0DD07BF2B7130DFC606A2885758CB7ADBC85E817B490BEF516B6625DED11DF3AEE215B8BAF8073C345E3958977609BE7AD77C1378D33142F13DB62C9AE1AA94F9867ADD420393071E08D6746E2C61CF40D5074412FE805246A216B49B092C4B239C742A56D5C184AAB8FD78E833E780A47D8A4B28423C3E2F27B66B14A74BD26414B9C6114604E30C882F3D00B707CEE554D77D2085576810203010001
Find the element for < PackageFile Name="dotNetFX30\XPSEPSC-amd64-en-US.exe" and change the PublicKey value to the same as in step 4 above
Save the product.xml file
Download and Extract the Core Installation Files
Navigate to the following URL: http://go.microsoft.com/fwlink?LinkID=118080
Download the dotNetFx35.exe file to your local disk.
Open a Command Prompt window and change to the directory to which you downloaded dotNetFx35.exe.
At the command prompt, type:
dotNetFx35.exe /x:.
This will extract the Framework files to a folder named “WCU” in the current directory.
Copy the contents of the WCU\dotNetFramework folder and paste them in the %Program Files%\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages\DotNetFx35SP1 folder (%ProgramFiles(x86)%\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages\DotNetFx35SP1 on x64 operating systems). Note: Do not copy the WCU\dotNetFramework folder itself. There should be 5 folders under the WCU folder, and each of these should now appear in the DotNetFx35SP1 folder. The folder structure should resemble the following:
o DotNetFx35SP1 (folder)
dotNetFX20 (folder
dotNetFX30 (folder)
dotNetFX35 (folder)
dotNetMSP (folder)
TOOLS folder)
en (or some other localized folder)
dotNetFx35setup.exe (file)
You may now delete the files and folders you downloaded and extracted in steps 2 and 4.
Found at Microsoft Solutions
For VS 2015, here is a very simple solution (including some Michael Eakins answer):
Download the installer here:
http://go.microsoft.com/fwlink?LinkID=118080
Extract / open with 7zip or Winrar and extract the contence to a folder
Copy/move everything under the extracted folder "wcu\dotNetFramework" path to:
C:\Program Files (x86)\Microsoft Visual Studio 4.0\SDK\Bootstrapper\Packages\DotNetFX35SP1
Publish in VS2015

Resources