Showing posts with label Visual Studio. Show all posts
Showing posts with label Visual Studio. Show all posts

Sunday, June 3, 2018

[Visual Studio] Same assembly information for all project in a solution


 Visual Studio   Assembly Information   



▌Introduction


Our goal is not to edit every project’s assembly information one by one in a visual studio’s solution.
The way is using the same one and make others have reference on it by using link file.



▌Environment


▋Visual Studio 2017 community


▌Implement


▋Create global Assembly information file

Create a solution folder, like “Assembly” for example, and find AssemblyInfo.cs file in any project.
Copy it and paste it to the Assembly folder. We will call it as “Global assembly file” in the later article to distinguish from the projects’ ones.






▋Update it

I suggest to update the Title and Product name in the global assembly file.

[assembly: AssemblyTitle("Wahlee.Infra")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Wahlee.Infra")]
[assembly: AssemblyCopyright("Copyright ©  2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]



▋Reference it

Here are two ways to make a project reference the global assembly file.

1.  Remove the exist AssemblyFile.cs, then add an exist item – the global assembly file, by “Add As Link”.



Or use the bellow manual way.


2.  Open project’s .csproj file, paste the following settings inside it.

<ItemGroup>
    <Compile Include="..\Assembly\AssemblyInfo.cs">
      <Link>Properties\AssemblyInfo.cs</Link>
    </Compile>
</ItemGroup>

Don’t forget to update the path for your own custom path.





▌Reference






Thursday, April 12, 2018

[ProGet] Installation tips and Setup (NuGet)


  ProGet    Nuget Package  




▌Introduction


We will learn some tips for installing and setting ProGet and upload first nuget package to it.



▌Environment


▋ProGet 5.0.11
▋Windows Server 2008 R2



▌Installation


▋Download



▋Install

Before you start the installation, create a new database in SQL Server.
Run the .exe and follow the official installation guide.




▋Trouble shooting

When installing ProGet, I encountered the following error.

The database could not be exclusively locked to perform the operation.
ALTER DATABASE failed. Cannot set database XXX’s default collation as SQL_Latin1_General_CP1_CI_AS

System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   於 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   於 System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   於 System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite)
   於 System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   於 System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   於 Inedo.ProGet.Setup.InstallProGetTask.CheckCreateDB()
   於 Inedo.ProGet.Setup.InstallProGetTask.Install()
   於 Inedo.Installer.InstallationTask`1.Inedo.Installer.IInstallationTask.RunInternal()
ClientConnectionId:59abd9f0-3013-4b14-be74-1f8e3344e424
Error Number:5030,State:2,Class:16






One of the solution is to set the database to single user manually.

ALTER DATABASE [Your_DbName] SET SINGLE_USER WITH ROLLBACK IMMEDIATE


PS. Don’t forget to set it back as MULTI_USER after installation.

ALTER DATABASE [Your_DbName] SET MULTI_USER WITH ROLLBACK IMMEDIATE



However, it didn’t work for me.
I finally solved this issue by manually executing the ALTER DATABASE sql like this,

ALTER DATABASE [DbName] SET SINGLE_USER WITH ROLLBACK IMMEDIATE

ALTER DATABASE [DbName]
COLLATE SQL_Latin1_General_CP1_CI_AS ;
GO

ALTER DATABASE [DbName] SET MULTI_USER WITH ROLLBACK IMMEDIATE


Done!




▌Setup and upload a NuGet package



▋Setup

Now open http://server-name:8624 and login as Admin. (Default ID/PWD: Admin/Admin)


Then create a new Feed



Select NuGet as following.



For more information about setting the Feed, see document.


Since we have a Feed, create an api key for it.







▋Upload a nupkg package

Use either of the following ways to upload a NuGet package.

2.      NuGet CLI

▋NuGet Package Explorer

【FILE】→【Publish】

Publish Url: http://server-name/nuget/Feed-name/
Publish key: The API key




▋NuGet CLI

$ nuget push MyPackage.nupkg -ApiKey XXXXXXXXX -source http://server-name/nuget/Feed-name/



Now you can add the NuGet package Feed (http://server-name/nuget/Feed-name/)
into Visual Studio: Package Sources.


Enjoy it!



▌Reference





Tuesday, November 7, 2017

[.NET] Build multiple frameworks in a project

 .NET   .NET framework target


▌Introduction


We will learn how to build multiple .NET frameworks in a project


▌Environment


▋Visual Studio 2017 community



▌Implement


▋Set new configuration

In Visual Studio, go to 【Configuration Manager】 as following.




Select <New…>







▋Set target .NET framework

Open your project setting file (*.csproj in a C# class library)

Find the section

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug-net45|AnyCPU'">
  ...
</PropertyGroup>

Which Debug-net45 is your new config name.

Add the following setting to indicate the target framework version.

<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>


▋Build

Now build and we get the different target framework in bin/



If the DLL and files ain't be built, go check the solution's property: Configuration Properties->Configuration.





▌Reference


Saturday, October 21, 2017

[Visual Studio] Create solution template

 Visual Studio    Project template   Solution template


▌Introduction


A sample for creating a solution template with multiple project templates.


▋Related articles



▌Environment


▋Visual Studio 2017 community



▌Samples


I created a sample solution like this,





▋Export needed projects






And that will create two zip files.




▋Project template

Now extract the zip files and just keep the extracted folders as following.




You can still edit the template metadata in MyTemplate.vstemplate for each project template.






▋Create solution level .vstemplate

Create an xml file named Root.vstemplate

$ copy nul> Root.vstemplate


PS. Icon is optional.



▋Root.vstemplate

<VSTemplate Version="3.0.0" Type="ProjectGroup" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
  <TemplateData>
    <Name>JB's Template</Name>
    <Description>A Solution Template sample</Description>
    <ProjectType>CSharp</ProjectType>
    <ProjectSubType>
    </ProjectSubType>
    <SortOrder>1000</SortOrder>
    <CreateNewFolder>true</CreateNewFolder>
    <DefaultName>JB.AspnetCore</DefaultName>
    <ProvideDefaultName>true</ProvideDefaultName>
    <LocationField>Enabled</LocationField>
    <EnableLocationBrowseButton>true</EnableLocationBrowseButton>
    <Icon>favicon.ico</Icon>
  </TemplateData>
  <TemplateContent>
    <ProjectCollection>
      <ProjectTemplateLink ProjectName="$projectname$.AspnetCore.Website">
        JB.AspnetCore.Website\MyTemplate.vstemplate
      </ProjectTemplateLink>
      <ProjectTemplateLink ProjectName="$projectname$.AspnetCore.Service">
        JB.AspnetCore.Website\MyTemplate.vstemplate
      </ProjectTemplateLink>
    </ProjectCollection>
  </TemplateContent>
</VSTemplate>


▋Pack the solution template

Compress all the project template folders, icon and Root.vstemplate to a zip file.



Copy it to ~\Documents\Visual Studio {version}\Templates\ProjectTemplates

And now we can create a visual studio solution with this solution template.







▌Reference