Showing posts with label visual-studio-2013. Show all posts
Showing posts with label visual-studio-2013. Show all posts

Tuesday, September 26, 2017

Publish from Visual Studio and automatically encrypt appSettings using aspnet_regiis

Leave a Comment

I have web application that is deployed to my local IIS server under Sites\Default, it works fine and right now I want to make it more secure - I want to encrypt connection strings and appSettings.
Inside pubxml file I've added this line:

<MSDeployEnableWebConfigEncryptRule>true</MSDeployEnableWebConfigEncryptRule> 

but that only encrypts connections strings. I know that I can manually call:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis -pe "appSettings" -site Default -app "/" 

on my server after deploy to encrypt external file containing appSettings, but I must do that manually.

My question is how can I deploy website from Visual Studio (Build > Publish) and have that aspnet_regiis command execute automatically after publish succeeded.

I found information that I could use runcommand and other about bat files, but I'm not calling MSDeploy from command line.
I've also found information that I should build custom provider and call it from MSDeploy.

How should I edit my pubxml file to get this behaviour?

EDIT1:
I've managed to hook After Deploy Target using:

<Target Name="EncryptAppSettings" AfterTargets="MSDeployPublish" >   <Message Text="Encrypting appSettings" />   <Exec Command="aspnet_regiis -pe &quot;appSettings&quot; -site Default -app &quot;/&quot;" />   <Message Text="AppPath: $(DeployIisAppPath)" /> </Target> 

But now I get this error:

The command "aspnet_regiis -pe "appSettings" -site Default -app "/"" exited with code 9009.

EDIT2:
I've tried using runCommand like this:

<ItemGroup>   <MsDeploySourceManifest Include="runCommand">     <path>aspnet_regiis -pe &quot;appSettings&quot; -site Default -app &quot;/&quot;</path>     <waitInterval>10000</waitInterval>     <AdditionalProviderSettings>waitInterval</AdditionalProviderSettings>   </MsDeploySourceManifest> </ItemGroup> 

but I had no luck. I found blog about postSync:runCommand, but I'd like to call that directly from VS so I'd like to add that to publish profile.

EDIT3:
I'm adding my publish profile below:

<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">   <PropertyGroup>     <WebPublishMethod>MSDeploy</WebPublishMethod>     <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>     <LastUsedPlatform>Any CPU</LastUsedPlatform>     <SiteUrlToLaunchAfterPublish />     <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>     <ExcludeApp_Data>False</ExcludeApp_Data>     <MSDeployServiceURL>192.168.5.50</MSDeployServiceURL>     <DeployIisAppPath>Default</DeployIisAppPath>     <RemoteSitePhysicalPath />     <SkipExtraFilesOnServer>False</SkipExtraFilesOnServer>     <MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>     <EnableMSDeployBackup>True</EnableMSDeployBackup>     <MSDeployEnableWebConfigEncryptRule>True</MSDeployEnableWebConfigEncryptRule>     <UserName>LocalAdmin</UserName>     <_SavePWD>True</_SavePWD>     <PublishDatabaseSettings>       <Objects xmlns="">         <ObjectGroup Name="ApplicationDbContext" Order="1" Enabled="False">           <Destination Path="Data Source=192.168.5.51;Initial Catalog=GameBit;User ID=GUser;Password=MyRealPassword;Application Name=EntityFramework" Name="Data Source=192.168.5.51;Initial Catalog=GameBit;User ID=GUser;Password=MyRealPassword;MultipleActiveResultSets=True;Application Name=EntityFramework" />           <Object Type="DbCodeFirst">             <Source Path="DBContext" DbContext="Api.ApplicationDbContext, Api" Origin="Configuration" />           </Object>         </ObjectGroup>       </Objects>     </PublishDatabaseSettings>   </PropertyGroup>    <PropertyGroup>     <UseMsdeployExe>true</UseMsdeployExe>     <AllowUntrustedCertificate>True</AllowUntrustedCertificate>   </PropertyGroup>    <ItemGroup>     <MSDeployParameterValue Include="$(DeployParameterPrefix)ApplicationDbContext-Web.config Connection String">       <ParameterValue>metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string="Data Source=192.168.5.51;Initial Catalog=GameBit;User ID=GUser;Password=MyRealPassword;MultipleActiveResultSets=True;Application Name=EntityFramework"</ParameterValue>     </MSDeployParameterValue>   </ItemGroup>    <!--<ItemGroup>   <MsDeploySourceManifest Include="runCommand">     <Path>dir</Path>   </MsDeploySourceManifest> </ItemGroup>-->     <!--<Target Name="EncryptImportantSettings" AfterTargets="MSDeployPublish" >     <Message Text="Encrypting appSettings" />     --><!--<Exec Command="aspnet_regiis -pe &quot;appSettings&quot; -site Default -app &quot;/&quot;" />--><!--   <ItemGroup>     <MsDeploySourceManifest Include="runCommand">       <path>dir/b >> C:\temp\log.txt</path>       --><!--<waitInterval>10000</waitInterval>--><!--       --><!--<AdditionalProviderSettings>waitInterval</AdditionalProviderSettings>--><!--     </MsDeploySourceManifest>   </ItemGroup>   <Message Text="AppPath: $(DeployIisAppPath)" />   </Target>--> </Project> 

I've noticed that when I use MSDeploy I can see command that is executed during publish:

"C:\Program Files (x86)\IIS\Microsoft Web Deploy V3\msdeploy.exe" -source:manifest='D:\GameBit\API\obj\Release\Package\API.SourceManifest.xml' -dest:auto,ComputerName="https://192.168.5.50:8172/msdeploy.axd?site=Default",UserName='LocalAdmin',Password="MyRealPassword",IncludeAcls='False',AuthType='Basic' -verb:sync -enableRule:EncryptWebConfig -enableRule:EncryptWebConfig -disableLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateExtension -setParamFile:"D:\GameBit\API\obj\Release\Package\API.Publish.Parameters.xml" -allowUntrusted -retryAttempts=2 -userAgent="VS12.0:PublishDialog:WTE12.5.60612.0"

Can I add -postSync:runCommand="" to that command from publish profile? As I found on MS site this parameter allows to execute command on destination machine.

EDIT4:
I found information about Web Deploy Operation Settings and postSync setting, but I don't know where to set it, I don't want to edit Microsoft.Web.Publishing.targets from MSBuild folder

I need to execute command on remote machine after publish succeeded.

1 Answers

Answers 1

After going through your all edits and a bit of research from me , you want to execute the following command after the publish from the Visual Studio

C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis -pe "appSettings" -site Default -app "/"  

If i understood right , You can try wrapping the ItemGroup in a Target with AfterTargets set to AddIisSettingAndFileContentsToSourceManifest

<Target Name="executeinHosts" AfterTargets="AddIisSettingAndFileContentsToSourceManifest">     <ItemGroup>       <MsDeploySourceManifest Include="runCommand">          //here would be your path that need to run after the publish       </MsDeploySourceManifest>     </ItemGroup>   </Target> 

So in Your case this is how that part should look:

<Target Name="executeinHosts" AfterTargets="AddIisSettingAndFileContentsToSourceManifest">     <ItemGroup>       <MsDeploySourceManifest Include="runCommand">          <path>C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis -pe "appSettings" -site $(DeployIisAppPath) -app "/"</path>       </MsDeploySourceManifest>     </ItemGroup>   </Target> 
Read More

Tuesday, August 22, 2017

MVC 5 - Precompiling views only works from the command prompt

Leave a Comment

I have a strange issue that hopefully someone can help me with. I got a new laptop and I'm trying to publish the same ASP.NET MVC 5 project on the new machine with precompiled views. However, when I do a publish with "Precompile during publishing" option checked, it does not create the precompiled views. Now, if I copy the exact command that it ran and run it in the Command Prompt, the precompiled views are created.

Here's the details. Both machine have Windows 10 Anniversary Update (Version 1607) with Visual Studio 2013 Update 5. Publishing the app on the old machine with the same publish profile generates the precompiled views. On the new machine, publishing from the "Publish Web" dialog runs without errors, but no precompiled views are generated. I then copied this exact command to the Command Prompt that VS used to precompile:

C:\windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe -v / -p C:\MyApp\obj\Release\AspnetCompileMerge\Source -c C:\MyApp\obj\Release\AspnetCompileMerge\TempBuildDir 

When I ran it, it created the precompiled views in the TempBuildDir\bin directory!

The only difference I can think of between the machines are the Windows Updates.

Any ideas? Thanks.

1 Answers

Answers 1

Do you use the x64 verson of Windows?

Also you can try set $(AspnetCompilerPath) manually:

msbuild.exe /p:AspnetCompilerPath="C:\windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe" 

or add it to your project:

<PropertyGroup>   <AspnetCompilerPath Condition=" '$(AspnetCompilerPath)'=='' " >C:\windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe</AspnetCompilerPath> </PropertyGroup> 

I've made this assumption, because the Microsoft.Web.Publishing.AspNetCompileMerge.targets file contains the string:

 We can't use the in-place aspnet_compiler because it will output to the aspnet temp folder which is only suiteable to run on the current machine. 
Read More

Monday, February 6, 2017

Visual Studio Yellow Tooltip stuck on screen

Leave a Comment

I'm running VS2013 Professional on Windows 7 x64 and often finding that, after a debug session, the yellow tooltips from the debugger don't go away and stay on the screen on top of other windows. For example, the image attached shows a debug tooltip now also showing on top of me posting this question.

enter image description here

I am able to hide it temporarily by pressing Win + d to show the desktop, but as soon as I open / navigate to any window, the tooltip is right back.

The only way I've been able to get rid of these tooltips has been to close and re-open my Visual Studio. Any thoughts about what else I could do?

1 Answers

Answers 1

On your screenshot, the tooltip is "this is the next statement that will be executed". This tooltip appears when you hover over a yellow arrow to the left of the code while stepping in debugger (there must be no breakpoint on the current line).

It's quite likely that when the tooltip is stuck, you can un-stuck it by howering over that yellow arrow again, then moving mouse cursor away from it.

As for permanent solution to the problem, I would blame third-party applications that install hooks. Try to temporarily disable whatever such software you have and see if it helps. If you can't figure the exact repro to get the problem, you can simply close any other software you can and do your debugging for a while.

Some typical examples of hooking software:

  1. Input assistance (voice to text, ...)
  2. Automatic keyboard layout correction
  3. Dictionary and language translation
  4. Anything that creates new buttons in other programs
  5. Screenshot software
Read More

Monday, October 10, 2016

Visual Studio 2013 Pro: I've lost ability to browse class members in Solution Explorer

Leave a Comment

Like the subject says, I've suddenly lost the ability to view class members (properties and methods, or any structure at all) from the Solution Explorer. I've looked in settings unsuccessfully (not that I changed anything), and have tried cleaning the solution, rebuilding, restarting Visual Studio, etc. to no avail. What could be causing this? Thank you.

5 Answers

Answers 1

This setting is controlled by the UseSolutionNavigatorGraphProvider registry value from HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0.

If you have the VSCommands extension installed, you can control it from Tools - Options - VSCommands 12 - IDE Enhancements - Solution Explorer - Disable Graph provider.

Answers 2

Try using the extension below it might help:

Disable Solution Explorer's Dynamic Nodes

Answers 3

Checkout the below link and enable the settings (set the value to 1) and see if that works.

https://visualstudioextensions.vlasovstudio.com/2013/11/04/hide-class-info-in-visual-studio-20122013-solution-explorer/

Answers 4

Is it website project or web application project? We couldn't see any class member hierarchy in website project.

Answers 5

You can find it in view dropdown menu! and if not then clear your question more please

Read More

Friday, April 22, 2016

How to point sql server unit test project to localdb depending on visual studio version?

Leave a Comment

I have a Sql Server database unit test project that I set up following the instructions here: https://msdn.microsoft.com/en-us/library/jj851212(v=vs.103).aspx.

I have everything working perfectly ON MY MACHINE. I have visual studio 2013 Ultimate edition, which means my localdb connection string in my app.config for my unit test project points to the server (localdb)\ProjectsV12.

The problem is that some of my co-workers have professional edition, which means their db lives under: (localdb)\Projects. So they will have to alter the connection string in the app.config if they check it out from TFS and run the unit tests. I'd like it to be as seamless as possible so they don't have to do anything special -- just check out the project, build and run the tests.

How can I solve this so that the unit test project will point to the correct localdb server depending on your version of VS?

2 Answers

Answers 1

It is a problem with migrating projects between different versions of VS. As soon as you open a project with any version other than the version that the project was created in the migration wizard would pop up with the usual questions about SQL Express and LocalDb. But the main issue related to your question seems to be that of organizing your test code folder structure.

  1. Set up your folder structure as same as in TFS. One simple way to make this happen is to go to Visual Studio Online and create a new team test project with a root folder call 'test'. Give access rights to all in the team. Connect using your VS client and map your local repository and then check in your project. Let your team do the same.

Answers 2

I found a solution from the following blog post: https://blogs.msdn.microsoft.com/ssdt/2014/07/24/sql-server-database-projects-and-team-foundation-build/#unitTests

By having everyone run the following command, I determined that everyone had an instance named (localdb)\v11.0

%ProgramFiles%\Microsoft SQL Server\120\Tools\Binn\SqlLocalDB.exe i 

or alternatively:

"%ProgramFiles%\Microsoft SQL Server\110\Tools\Binn\SqlLocalDB.exe" i 

For now, I will point the app.config connection string to v11.0. If I discover that for some reason this instance won't work for a particular database project or someone doesn't have an instance with that name, I will add a prebuild step to install an instance under ProjectsV12:

"%ProgramFiles%\Microsoft SQL Server\120\Tools\Binn\SqlLocalDB.exe" create ProjectsV12 -s 

According to the blog:

If you want your database unit test to deploy the database to LocalDB\ProjectsV12, you will need to add a pre-test script to your build to create the instance. Running this command multiple times is safe.

Read More

Sunday, April 3, 2016

Issue trying to create a Ado.Net Entity Model Visual Studio 2013

Leave a Comment

I recently installed Visual Studio 2013 Professional, after install VS I installed MySql for VisualStudio version 1.2.6 that it is the latest release. The problem is when I tried to create a ADO .Net Entity Model I created the connection perfectly fine but when I press Next the window close it self and Visual Studio doesn't create the model.

Things that I checked:

  1. I already have installed in my project the Entity Framework 6, MySQL.Data V6.9.8, MySQL.Data.Entity.EF6 v6.9.8 and MySql.Web v6.9.8.
  2. In the Visual Studio Private Libraries there there is the three same libraries with the same version.

I checked other posts here and I really don't find the cause of my problem. I will be very grateful with any help.

Edit

I attached the process to another instance of Visual Studio and I got this:

'devenv.exe' (CLR v4.0.30319: ProjectExecutionContextDomain): Unloaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Numerics\v4.0_4.0.0.0__b77a5c561934e089\System.Numerics.dll' 'devenv.exe' (CLR v4.0.30319: ProjectExecutionContextDomain): Unloaded 'C:\Users\Jose\AppData\Local\assembly\dl3\3C4YP8TT.W35\4414OC0M.0ZV\4aeb0621\323bbd39_5088d101\SignaSafePro.dll' 'devenv.exe' (CLR v4.0.30319: ProjectExecutionContextDomain): Unloaded 'C:\Users\Jose\AppData\Local\assembly\dl3\3C4YP8TT.W35\4414OC0M.0ZV\77badc31\29b0d95d_4088d101\EntityFramework.SqlServer.dll' 'devenv.exe' (CLR v4.0.30319: ProjectExecutionContextDomain): Unloaded 'C:\Users\Jose\AppData\Local\assembly\dl3\3C4YP8TT.W35\4414OC0M.0ZV\27b7b188\7ad46db4_4f88d101\MySql.Data.Entity.EF6.dll' A first chance exception of type 'System.ArgumentException' occurred in System.Data.dll A first chance exception of type 'Microsoft.VisualStudio.TemplateWizard.WizardCancelledException' occurred in Microsoft.Data.Entity.Design.dll The thread 0x908 has exited with code 259 (0x103). 

I also uninstall and install all again, the libraries references are exactly the same, because I'm reference the libraries from the PrivateAssemblies folder.

2 Answers

Answers 1

Guys thank you very much, the problem was my mistake, I thought if I installed just MySQL for Visual Studio was enough but I didn't realized that the MySQL Connector is needed to: MySQL Connector/Net Developer Guide

I hope it serve to guide for anyone other like me.

Answers 2

Requirements

  • Windows OS 7 or later.
  • Visual Studio 2010, 2012 or 2013 Professional or higher version.
  • Connector/Net 6.8.1 beta or higher version (MySQL Connector download link).

Additional download links (not required)

Read More

Thursday, March 17, 2016

visual studio 2012 / 2013 single click opens file

Leave a Comment

In my Visual Studio 2012 solution explorer, when I single click a filename it opens it. This was different from VS2010 (required a double click). Is there a way to make double-click the 'view file' command?

5 Answers

Answers 1

This is where you change that behavior (in VS2012 and VS 2013):

enter image description here

Answers 2

Use the preview button to toggle it on solution explorer:

enter image description here

Answers 3

The Single-click opens files in the preview tab text mentioned in rubber boots' answer is missing in VS 2015. Mysteriously, a search for "single click" still brings up the Environment > Tabs and Windows option.

So for VS2015, either click the button in Vinicius's answer, or uncheck the Preview selected files in Solution Explorer box shown in the screenshot below.

enter image description here

Answers 4

Shortcut Ctrl+Alt+Home.

If you press that in a document that was just opened, it will be opened permanently.

Item -> right click -> Open With -> Source Code (Text) Editor -> press Set as Default button

Answers 5

In Visual studio 12/13, easiest way is to type "single click" in quick search and than select Tabs and Windows.

And in Tabs and Windows dialogue ,uncheck "Preview selected files in solutions explorer"

enter image description here

"

Read More

Thursday, March 10, 2016

Assembly Reference loads in Release, but not in Debug, Visual Basic 2013

Leave a Comment

I am not very experienced. Just trying to make some changes to source code that someone else wrote.

I had to add a reference to a .dll to get it to work in "Release" mode. However when I try to get it to work in Debug, it does not work. (assembly reference not loaded).

Help?

2 Answers

Answers 1

It looks like the Chillkat dot net is a actually a mixed mode assembly and it's quiet possible that you need to have the appropriate c runtime as well. This exception and a way to fix this is documented here

Hope this helps.

Answers 2

Typically I get this error when the executable is x86 and the dll it's referencing is x64. Check your build configurations to make sure it's targeting the correct platform.

In VS2013 go to Build -> Configuration Manager. There should be a drop down in the top left of the new window which contains the different build modes. Compare Debug to Release.

Read More

Monday, March 7, 2016

The way Visual Studio handles backward/forward navigation

Leave a Comment

Here is an example of backward/forward navigation in Visual Studio:
I'm in file1, I go to symbol which is in file2, then go to other symbol which is in file3.
At this point navigation works perfect - both forward and backward.
Then let's say I'm in file3 and I close it - it gets me to file2.

Here starts the dramatic difference between VS2010 and VS2013:
If I press Navigate backward in VS2010 it positions me to file1 - i.e. it is intelligent enough to understand that I closed file3 myself and it excludes it from navigation chain.
VS2013 reopens file3 instead of getting me to file1.
This is inconvenient and confusing.

Is there any way to control it?

0 Answers

Read More