visual studio customize the default build properties - c#

MyApp.csproj
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<UseWindowsForms>true</UseWindowsForms>
<TargetFrameworks>net48;net5.0-windows</TargetFrameworks>
<Configurations>Release</Configurations>
<Platforms>AnyCPU;x64;x86</Platforms>
<RuntimeIdentifiers>win-x64;win-x86</RuntimeIdentifiers>
<SelfContained>false</SelfContained>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64' And '$(TargetFramework)'=='net5.0-windows' And '$(RuntimeIdentifier)'=='win-x64'">
<OutputPath>..\..\app\</OutputPath>
<AssemblyName>my-app</AssemblyName>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x86' And '$(TargetFramework)'=='net5.0-windows' And '$(RuntimeIdentifier)'=='win-x86'">
<OutputPath>..\..\x86\app\</OutputPath>
<AssemblyName>my-app</AssemblyName>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
</PropertyGroup>
</Project>
these commands build both x64 and x86 assemblies in "....\app" and "....\x86\app" folders
msbuild.exe "MyApp.csproj" /t:restore;rebuild /p:RuntimeIdentifier=win-x64
msbuild.exe "MyApp.csproj" /t:restore;rebuild /p:RuntimeIdentifier=win-x86
but clicking Build (Ctrl+F5) or Debug (F5) in Visual Studio outputs to "bin\Release\net5.0-windows" directory.
how to force Build (Ctrl+F5) and Debug (F5) to do the same as this command:
msbuild.exe "MyApp.csproj" /t:restore;rebuild /p:RuntimeIdentifier=win-x64

Here is my code:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFrameworks>net5.0-windows;net472</TargetFrameworks>
<Nullable>disable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<Configurations>Release</Configurations>
<Platforms>AnyCPU;x64;x86</Platforms>
<SelfContained>false</SelfContained>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutputPath>..\..\app\</OutputPath>
<AssemblyName>my-app</AssemblyName>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x86'">
<OutputPath>..\..\x86\app\</OutputPath>
<AssemblyName>my-app</AssemblyName>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
</PropertyGroup>
</Project>
You can refer to the following steps to solve this problem:
1.Select target framework .net5.0-windows
2.Choose Platform x86
3.Debug your project with the button or F5
4.Change Platform x64 and Debug it.
5.Finally we can get these folders.

Related

dotnet pack generates dll if I add a readme file?

CSProj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageId>Org.AppName</PackageId>
<PackageVersion>1.0.0</PackageVersion>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
</Project>
If I exclude the PackageReadmeFile, it complains when uploading it needs a README, although if I add PackageReadmeFile then dotnet pack generates a dll not a nuget package file?

MSB3021 not copy file -> access denied

I wnat to change some code in application. I decompose some libs and want to compile changed files. I have next csproj file:
<PropertyGroup>
<AssemblyName>Siemens.Simatic.Hwcn.Basics</AssemblyName>
<GenerateAssemblyInfo>False</GenerateAssemblyInfo>
<UseWindowsForms>True</UseWindowsForms>
<TargetFramework>net461</TargetFramework>
<PlatformTarget>x64</PlatformTarget>
<UseCommonOutputDirectory>true</UseCommonOutputDirectory>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
</PropertyGroup>
<PropertyGroup>
<LangVersion>7</LangVersion>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup>
<RootNamespace />
<OutputPath>C:\Program Files\Siemens\Automation\Portal V15_1\Bin</OutputPath>
</PropertyGroup>
And when I build solution display error:
Unable to copy file "obj\Debug\Siemens.Simatic.Hwcn.Basics.dll" в "C:\Program Files\Siemens\Automation\Portal V15_1\Bin\Siemens.Simatic.Hwcn.Basics.dll". The process cannot access the file "C:\Program Files\Siemens\Automation\Portal V15_1\Bin\Siemens.Simatic.Hwcn.Basics.dll".
Just open Visual Studio with admin access

How prevent copy unnecessary libraries on publish

I have three simple projects:
SampleApp.Cli1
SampleApp.Cli2
SampleApp.Lib
SampleApp.Cli1 use Microsoft.Extensions.Configuration directly
SampleApp.Cli2 uses Microsoft.Extensions.Configuration through SampleApp.Lib
SampleApp.Cli1:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<OutputType>Exe</OutputType>
<OutputPath>../_out1</OutputPath>
<TargetFramework>netcoreapp3.1</TargetFramework>
<NoDefaultLaunchSettingsFile>true</NoDefaultLaunchSettingsFile>
</PropertyGroup>
</Project>
SampleApp.Cli2:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<OutputType>Exe</OutputType>
<OutputPath>../_out2</OutputPath>
<TargetFramework>netcoreapp3.1</TargetFramework>
<NoDefaultLaunchSettingsFile>true</NoDefaultLaunchSettingsFile>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\SampleApp.Lib\SampleApp.Lib.csproj" />
</ItemGroup>
</Project>
SampleApp.Lib:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.6" />
</ItemGroup>
</Project>
Script for publishing:
#echo off
if exist "%~dp0_out1" (
rd "%~dp0_out1" /s /q
)
if exist "%~dp0_out2" (
rd "%~dp0_out2" /s /q
)
dotnet publish "%~dp0SampleApp.Cli1/SampleApp.Cli1.csproj"
dotnet publish "%~dp0SampleApp.Cli2/SampleApp.Cli2.csproj"
After build
publish dir for SampleApp.Cli1 contains this files
web.config
SampleApp.Cli1.deps.json
SampleApp.Cli1.dll
SampleApp.Cli1.exe
SampleApp.Cli1.pdb
SampleApp.Cli1.runtimeconfig.json
publish dir for SampleApp.Cli2 contains this files
SampleApp.Lib.pdb
web.config
Microsoft.Extensions.Configuration.Abstractions.dll
Microsoft.Extensions.Configuration.dll
Microsoft.Extensions.Primitives.dll
SampleApp.Cli2.deps.json
SampleApp.Cli2.dll
SampleApp.Cli2.exe
SampleApp.Cli2.pdb
SampleApp.Cli2.runtimeconfig.json
SampleApp.Lib.dll
Question
For some unknown for me reason, the publication understands that for SampleApp.Cli1 Microsoft.Extensions.* must be taken from the shared runtime(Program Files\dotnet\shared\Microsoft.AspNetCore.App), but does not understand the same for SampleApp.Cli2. Of course, I understand that the matter is most likely in SampleApp.Lib(in real application it was Microsoft.Extensions.Hosting.WindowsServices).
In my situation, I have to build all libraries from sources that go into the publish folder. In real application Microsoft.Extensions.* libraries much more, and I would not really like to build all libraries from asp net core runtime.
Is any way to prevent copy(publish) Microsoft.Extensions.* libraries?
Sdk: 3.1.6

Visual Studio 2017 keeps using outdated Debug builds of referenced projects when publishing

I have a project set up like this:
MainProject.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
<RuntimeIdentifiers>win10-x64;ubuntu.16.04-x64</RuntimeIdentifiers>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Project1\Project1.csproj" />
<ProjectReference Include="..\Project2\Project2.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="mark.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
Project1.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFrameworks>netstandard1.6;net452</TargetFrameworks>
<OutputTypeEx>library</OutputTypeEx>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>1.0.16</Version>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
<DebugType>full</DebugType>
<DebugSymbols>True</DebugSymbols>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netstandard1.6|AnyCPU'">
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netstandard1.6|x64'">
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Reflection.Emit" Version="4.3.0" />
<PackageReference Include="System.Runtime" Version="4.3.0" />
<PackageReference Include="System.ValueTuple" Version="4.3.1" />
</ItemGroup>
</Project>
Project2.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard1.6;net452</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Project1\Project1.csproj" />
</ItemGroup>
</Project>
I have configured publishing the project using Right click -> Publish like this:
Profile Name: FolderProfile
Configuration: Release
Target Framework: netcoreapp1.1
Target Runtime: win10-x64
Target Location: bin\Release\PublishOutput\Win10
Whenever I try to publish the project (in release mode), Visual Studio decides to use old Debug-builds of Project1 and Project2 instead of the new Release builds. I have traced the issue to the Roslyn csc command that Visual Studio is executing. In the output console I see this:
[ Build output of all Release builds ]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Roslyn\csc.exe /noconfig /unsafe- /checked- /nowarn:1701,1702,1705,2008 /nostdlib+ /platform:x64 /errorreport:prompt /warn:4 /define:TRACE;RELEASE;NETCOREAPP1_1 /errorendlocation /preferreduilang:en-US [...] /reference:D:\Workspace\MySolution\Project1\bin\Debug\netstandard1.6\Project1.dll /reference:D:\Workspace\MySolution\Project2\bin\Debug\netstandard1.6\Project2.dll [...]
Note how it's actually using the bin\Debug files instead of the bin\Release files.
How do I force Visual Studio to use the Release builds instead of the outdated Debug builds when publishing?

Visual Studio C# project in Monodevelop - Errors for GenerateSatelliteAssemblies and GenerateTargetFrameworkMonikerAttribute

I am trying to setup a C# project that is compatible with both Windows 10 / Visual Studio 2015 and Ubuntu 16.04 / MonoDevelop.
In the MonoDevelop project options, I set the target framework to Mono / .NET 4.5 and configuration to Debug|x86.
The .csproj file now looks like this:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProjectGuid>{myprojectsguid}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>myproject</RootNamespace>
<AssemblyName>myproject</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
When I build, I get this message:
Erzeuge Projektmappe: myproject (Debug|x86)
myproject (Debug|x86) wird erzeugt
Build started 26.05.2016 22:05:49.
__________________________________________________
Project "pathto/myproject.csproj" (Build target(s)):
Target PrepareForBuild:
Configuration: Debug Platform: x86
Target GenerateSatelliteAssemblies:
No input files were specified for target GenerateSatelliteAssemblies, skipping.
Target GenerateTargetFrameworkMonikerAttribute:
Skipping target "GenerateTargetFrameworkMonikerAttribute" because its outputs are up-to-date.
Done building project "pathto/myproject.csproj".-- FAILED
Build FAILED.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:00.0785520
--------------------- Fertig ---------------------
Erzeugung erfolgreich.
The message seems to contradict itself. The English part says "build failed", while the localized/German part says "build successful". But no executable was created.
I did not find any applicable information about GenerateSatelliteAssemblies or GenerateTargetFrameworkMonikerAttribute.
Do I need to change the project settings even further? Do I need to supply some missing files?
Update:
Apparently, some packages were missing. So I ran sudo apt-get install mono-complete. Now the project builds successfully.
Though, the notifications about GenerateSatelliteAssemblies and GenerateTargetFrameworkMonikerAttribute are still there. Looks like they don't break the build. I still wonder what they mean.
(I'm just posting the answer that the asker wrote in the question.)
For the asker, it turned out that some packages were missing. The asker ran sudo apt-get install mono-complete, and then the project would build successfully.

Categories