I'd like to build many web projects and output them to a directory such as ./output/Project1 ./output/Project2 etc. Each of these folders would contain essentially what's output to _PublishedWebsites. I've tried this:
msbuild support.sln /p:configuration=Release;DeployOnBuild=true;DeployTarget=Package;_PackageTempDir=c:/ws/code/supportsite/output/ /t:package
but it seems to overwrite the contents of the output directory with each project that's built.
Why not make target file.
XCopyWebDeploy.targets
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>
<XCopyDeployWebPackage Condition=" '$(XCopyDeployWebPackage)' == '' ">false</XCopyDeployWebPackage>
</PropertyGroup>
<ItemGroup>
<ProjectFileItem Include="$(ProjectPath)"/>
</ItemGroup>
<PropertyGroup>
<!-- Make the build depend on web deploy packages -->
<BuildDependsOn Condition="$(XCopyDeployWebPackage) == 'true'">
$(BuildDependsOn);
Package;
XCopyDeployWebPackage;
</BuildDependsOn>
</PropertyGroup>
<Target Name="XCopyDeployWebPackage">
<CreateItem Include="$(ProjectDir)obj\$(Configuration)\Package\PackageTmp\**\*.*">
<Output ItemName="XCopyWebDeployPackageOutputFiles" TaskParameter="Include"/>
</CreateItem>
<CreateProperty Value="c:\ws\code\supportsite\output\%(ProjectFileItem.Filename)">
<Output PropertyName="XCopyWebDeployOutput" TaskParameter="Value"/>
</CreateProperty>
<Copy
SourceFiles="#(XCopyWebDeployPackageOutputFiles)"
DestinationFiles="#(XCopyWebDeployPackageOutputFiles->'$(XCopyWebDeployOutput)\%(RecursiveDir)%(Filename)%(Extension)')"/>
</Target>
</Project>
And import in web project(s) file.
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>
</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{BF6B6392-1398-42D3-AA90-ED87D02D351A}</ProjectGuid>
<ProjectTypeGuids>{E3E379DF-F4C6-4180-9B81-6769533ABE47};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MvcApplication1</RootNamespace>
<AssemblyName>MvcApplication1</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<MvcBuildViews>false</MvcBuildViews>
<UseIISExpress>true</UseIISExpress>
<IISExpressSSLPort />
<IISExpressAnonymousAuthentication />
<IISExpressWindowsAuthentication />
<IISExpressUseClassicPipelineMode />
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<!--!!!-->
<XCopyDeployWebPackage>true</XCopyDeployWebPackage>
<!--!!!-->
</PropertyGroup>
<!-- Some lines omitted -->
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
<!--!!!-->
<Import Project="$(SolutionDir)\XCopyWebDeploy.targets" />
<!--!!!-->
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target> -->
</Project>
Related
I have a C# WPF project in Visual Studio 2019 that I'm trying to set the AssemblyVersion and AssemblyFileVersion of. The idea being that I am trying to set them to "0.Months since project started.Days since this month started.Minutes since midnight" to help with version control
I have a Text Template file with the code below
using System.Reflection;
[assembly: AssemblyVersion("<#= this.Release #>.<#= this.MonthsSinceProjectStarted #>.<#= this.DaysSinceMonthStarted #>.<#= this.MinutesSinceMidnight #>")]
[assembly: AssemblyFileVersion("<#= this.Release #>.<#= this.MonthsSinceProjectStarted #>.<#= this.DaysSinceMonthStarted #>.<#= this.MinutesSinceMidnight #>")]
<#+
int Release = 0;
static DateTime ProjectStartedDate = new DateTime(year: 2022, month: 5, day: 20);
int MonthsSinceProjectStarted = (int)((Int32.Parse(DateTime.Now.ToString("yyyy")) * 12) + Int32.Parse(DateTime.Now.ToString("MM"))) - ((ProjectStartedDate.Year * 12) ProjectStartedDate.Month);
int DaysSinceMonthStarted = (int)Int32.Parse(DateTime.Now.ToString("dd"));
int MinutesSinceMidnight = (int)DateTime.UtcNow.TimeOfDay.TotalMinutes;
#>
My .csproj file also looks like this
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<RootNamespace>LPG_Launcher</RootNamespace>
<UseWPF>true</UseWPF>
<Company>LowPoly Games</Company>
<Authors>LowPoly Games</Authors>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<PlatformTarget>x64</PlatformTarget>
<DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols>
<TransformOnBuild>true</TransformOnBuild>
<OverwriteReadOnlyOutputFiles>true</OverwriteReadOnlyOutputFiles>
<TransformOutOfDateOnly>false</TransformOutOfDateOnly>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<Optimize>true</Optimize>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<DebugType>full</DebugType>
<DebugSymbols>true</DebugSymbols>
<PlatformTarget>x64</PlatformTarget>
<TransformOnBuild>true</TransformOnBuild>
<OverwriteReadOnlyOutputFiles>true</OverwriteReadOnlyOutputFiles>
<TransformOutOfDateOnly>false</TransformOutOfDateOnly>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugType>full</DebugType>
<DebugSymbols>true</DebugSymbols>
<TransformOnBuild>true</TransformOnBuild>
<OverwriteReadOnlyOutputFiles>true</OverwriteReadOnlyOutputFiles>
<TransformOutOfDateOnly>false</TransformOutOfDateOnly>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols>
<PlatformTarget>x64</PlatformTarget>
<TransformOnBuild>true</TransformOnBuild>
<OverwriteReadOnlyOutputFiles>true</OverwriteReadOnlyOutputFiles>
<TransformOutOfDateOnly>false</TransformOutOfDateOnly>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<Optimize>true</Optimize>
</PropertyGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="if $(ConfigurationName) == Release (
del /S *.pdb
)" />
</Target>
<PropertyGroup>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<TransformOnBuild>true</TransformOnBuild>
<OverwriteReadOnlyOutputFiles>true</OverwriteReadOnlyOutputFiles>
<TransformOutOfDateOnly>false</TransformOutOfDateOnly>
</PropertyGroup>
<ItemGroup>
<None Include="VersionAutoIncrementer.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>VersionAutoIncrementer.txt</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v16.0\TextTemplating\Microsoft.TextTemplating.targets" />
</Project>
When I clean and build my solution, it builds a .cs file with the below code in it
using System.Reflection;
[assembly: AssemblyVersion("0.0.20.673")]
[assembly: AssemblyFileVersion("0.0.20.673")]
But checking the properties of the "LPG Launcher.exe" thats built is showing the version numbers to be "0.0.0.0". Is this a suitable method of setting these values and if so, what am I doing incorrectly?
After checking from information given in the comments, I've determined that the .cs file being built by the Text Template wasn't being included in the build process. Thanks for the help everyone
I'm upgrading a project from AspNet Mvc 4 to AspNet Core Mvc 2.2; I am attempting to migrate the msbuild build.proj file to set the version and other attributes for the projects that create dll's; everything is working except the GenerateAssemblyInfo task. Is there a new way to do this in netcoreapp2.2?
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="GetRevisionInfo" BeforeTargets="Build">
<GitPendingChanges ContinueOnError="WarnAndContinue">
<Output TaskParameter="HasPendingChanges" PropertyName="HasPendingChanges" />
</GitPendingChanges>
<!--This will throw git Error 128 if there are no Tags -->
<GitDescribe SoftErrorMode="true" Lightweight="true" ContinueOnError="WarnAndContinue">
<Output TaskParameter="Tag" PropertyName="Tag" />
<Output TaskParameter="CommitCount" PropertyName="CommitCount" />
<Output TaskParameter="CommitHash" PropertyName="CommitHash" />
</GitDescribe>
<GitBranch ContinueOnError="WarnAndContinue">
<Output TaskParameter="Branch" PropertyName="Branch" />
</GitBranch>
<PropertyGroup>
<ShortCommitHash Condition="'$(CommitHash)' != ''">$(CommitHash.Substring(0,6))</ShortCommitHash>
<ReleaseType Condition="'$(CommitCount)' != '' AND '$(CommitCount)' != '0'">Beta</ReleaseType>
<ReleaseType Condition="'$(Branch)' != '' AND '$(Branch)' != 'master'">Alpha</ReleaseType>
</PropertyGroup>
</Target>
<!-- Error out if this is a release and our working copy has uncommitted changes -->
<Target Name="CheckRelease" AfterTargets="GetRevisionInfo" Condition="'$(Configuration)' == 'Release'">
<Error Text="Cannot build a Release Version when there are uncommitted changes, commit or revert all changes." Condition="'$(CommitHash)' != '' AND '$(HasPendingChanges)' == 'True'" />
</Target>
<!-- Generates AssemblyInfo file using Git Describe -->
<Target Name="GenerateAssemblyInfo" AfterTargets="CheckRelease" Condition="'$(CommitHash)' != ''">
<Time>
<Output TaskParameter="Year" PropertyName="Year" />
</Time>
<AssemblyInfo
CodeLanguage="CS"
OutputFile="$(MSBuildProjectDirectory)\Properties\AssemblyInfo.cs"
AssemblyProduct="$(MSBuildProjectName) $(ReleaseType)"
AssemblyCompany="xxx xxx xxx, LLC"
AssemblyCopyright="Copyright © $(Year) xxx xxx xxx, LLC. All rights reserved."
AssemblyConfiguration="$(Configuration)-$(Platform)"
AssemblyVersion="$(Tag).$(CommitCount)"
AssemblyFileVersion="$(Tag).$(CommitCount)"
AssemblyInformationalVersion ="$(Tag)-$(CommitCount)-$(ShortCommitHash) $(ReleaseType)"
AssemblyTitle="$(Tag)-$(CommitCount)-$(CommitHash)"/>
</Target>
<!-- copy framework files to libraries -->
<Target Name="CopyLibraries" Condition="'$(MSBuildProjectName)' == 'BaseApplication'" AfterTargets="Build">
<CreateItem Include="$(TargetDir)xxx.*">
<Output TaskParameter="Include" PropertyName="CopyFiles" />
</CreateItem>
<Copy SourceFiles="$(CopyFiles)" DestinationFolder="$(MSBuildProjectDirectory)\..\libraries\xxx\$(Configuration)"/>
</Target>
<Target Name="CopyKendoUI" AfterTargets="AfterBuild">
<ItemGroup>
<KendoFiles Include="
$(TargetDir)kendo.mvc.*;
$(TargetDir)\**\Kendo.Mvc.resources.*;" />
</ItemGroup>
<Copy SourceFiles="#(KendoFiles)" DestinationFolder="$(MSBuildProjectDirectory)\..\libraries\kendoui\$(Configuration)\%(RecursiveDir)"/>
</Target>
</Project>
There were a few things preventing this from working in Visual Studio 2019 using .Net Core;
The name of the target cannot be "GenerateAssemblyInfo", if this is the name of the target, it just gets ignored, no error, warning, or message, the target just doesn't run...
In the csproj file for the project that the msbuild project is imported in, you need to add false, I added this right below the
You have to manually create the Properties folder if you set the OutputFile to be in that folder.
Below is the working build.proj file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="GetRevisionInfo" BeforeTargets="Build">
<GitPendingChanges ContinueOnError="WarnAndContinue">
<Output TaskParameter="HasPendingChanges" PropertyName="HasPendingChanges" />
</GitPendingChanges>
<!--This will throw git Error 128 if there are no Tags -->
<GitDescribe SoftErrorMode="true" Lightweight="true" ContinueOnError="WarnAndContinue">
<Output TaskParameter="Tag" PropertyName="Tag" />
<Output TaskParameter="CommitCount" PropertyName="CommitCount" />
<Output TaskParameter="CommitHash" PropertyName="CommitHash" />
</GitDescribe>
<GitBranch ContinueOnError="WarnAndContinue">
<Output TaskParameter="Branch" PropertyName="Branch" />
</GitBranch>
<PropertyGroup>
<ShortCommitHash Condition="'$(CommitHash)' != ''">$(CommitHash.Substring(0,6))</ShortCommitHash>
<ReleaseType Condition="'$(CommitCount)' != '' AND '$(CommitCount)' != '0'">Beta</ReleaseType>
<ReleaseType Condition="'$(Branch)' != '' AND '$(Branch)' != 'master'">Alpha</ReleaseType>
</PropertyGroup>
</Target>
<!-- Error out if this is a release and our working copy has uncommitted changes -->
<Target Name="CheckRelease" AfterTargets="GetRevisionInfo" Condition="'$(Configuration)' == 'Release'">
<Error Text="Cannot build a Release Version when there are uncommitted changes, commit or revert all changes." Condition="'$(CommitHash)' != '' AND '$(HasPendingChanges)' == 'True'" />
</Target>
<!-- Generates AssemblyInfo file using Git Describe -->
<Target Name="GenerateAssemblyInfo" AfterTargets="CheckRelease" Condition="'$(CommitHash)' != ''">
<Time>
<Output TaskParameter="Year" PropertyName="Year" />
</Time>
<AssemblyInfo
CodeLanguage="CS"
OutputFile="$(MSBuildProjectDirectory)\Properties\AssemblyInfo.cs"
AssemblyProduct="$(MSBuildProjectName) $(ReleaseType)"
AssemblyCompany="xxx xxx xxx, LLC"
AssemblyCopyright="Copyright © $(Year) xxx xxx xxx, LLC. All rights reserved."
AssemblyConfiguration="$(Configuration)-$(Platform)"
AssemblyVersion="$(Tag).$(CommitCount)"
AssemblyFileVersion="$(Tag).$(CommitCount)"
AssemblyInformationalVersion ="$(Tag)-$(CommitCount)-$(ShortCommitHash) $(ReleaseType)"
AssemblyTitle="$(Tag)-$(CommitCount)-$(CommitHash)"/>
</Target>
<!-- copy framework files to libraries -->
<Target Name="CopyLibraries" Condition="'$(MSBuildProjectName)' == 'BaseApplication'" AfterTargets="Build">
<CreateItem Include="$(TargetDir)xxx.*">
<Output TaskParameter="Include" PropertyName="CopyFiles" />
</CreateItem>
<Copy SourceFiles="$(CopyFiles)" DestinationFolder="$(MSBuildProjectDirectory)\..\libraries\xxx\$(Configuration)"/>
</Target>
<Target Name="CopyKendoUI" AfterTargets="AfterBuild">
<ItemGroup>
<KendoFiles Include="
$(TargetDir)kendo.mvc.*;
$(TargetDir)\**\Kendo.Mvc.resources.*;" />
</ItemGroup>
<Copy SourceFiles="#(KendoFiles)" DestinationFolder="$(MSBuildProjectDirectory)\..\libraries\kendoui\$(Configuration)\%(RecursiveDir)"/>
</Target>
</Project>
And the MyProject.csproj file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MSBuildTasks" Version="1.5.0.235">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.AspNetCore.Http.Abstractions">
<HintPath>C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.http.abstractions\2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Http.Abstractions.dll</HintPath>
</Reference>
</ItemGroup>
<Import Project="../.build/build.proj" />
</Project
In my company, we have some projects using .NET Framework (4.5.1) and one project using .NET Core.
Currently, all the .NET Framework projects are built with MSBuild.exe (version 12) and i would like to update the build to use MSBuild 15 so i would be able to build both .NET Framework and .NET Core projects in the same build.
Currently, the build compiles successfully when i'm building only my .NET Core project. But i wish to publish it, and the build result is not my desired outcome as it doesn't publish it correctly (the build results in the folders: bin, Properties, Views, wwwroot, and the configuration files).
I dont know what im doing wrong here, i have searched the web for a couple of days and still wasnt able to figure out what i did wrong. Please advice.
Note: to be able to build in the first place, i had to add to my .NET Core's project .csproj file the following lines so it wont fail while building:
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v15.0\WebApplications\Microsoft.WebApplication.targets" Condition="true" />
The command line to execute the build
"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild" DailyBuild.proj /t:DailyBuild /p:VersionNumber=15
DailyBuild.proj
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SourcesPath>$(MSBuildProjectDirectory)\..\..\</SourcesPath>
<CSCleanProperties>BuildType=Clean;Configuration=Release;IsFormalBuild=true</CSCleanProperties>
<CSBuildProperties>BuildType=ReBuild;Configuration=Release;PauseBuildOnError=false;PublishWebSites=true;VersionName=Prod-$(VersionNumber)</CSBuildProperties>
</PropertyGroup>
<Target Name="DailyBuildWithClean">
<MSBuild Projects="$(MSBuildProjectDirectory)\Make2.proj" Targets="Clean" Properties="$(CSCleanProperties)"/>
<MSBuild Projects="$(MSBuildProjectDirectory)\Make2.proj" Properties="$(CSCleanProperties)"/>
<MSBuild Projects="$(MSBuildProjectDirectory)\Make2.proj" Targets="FormalBuild" Properties="$(CSBuildProperties)"/>
</Target>
<Target Name="DailyBuild">
<MSBuild Projects="$(MSBuildProjectDirectory)\Make2.proj" Targets="SW;PreparePackFolder" Properties="$(CSBuildProperties)"/>
</Target>
</Project>
Make2.proj
<Project DefaultTargets="SW" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" InitialTargets="CreateProperties;Clean">
<ItemGroup>
<SourcesPathItem Include='$(MSBuildProjectDirectory)\..\..\' />
</ItemGroup>
<PropertyGroup>
<MSBuildCommunityTasksPath>$(MSBuildProjectDirectory)\MSBuild.Community.Tasks.v1.4.0.88</MSBuildCommunityTasksPath>
</PropertyGroup>
<Import Project="$(MSBuildCommunityTasksPath)\MSBuild.Community.Tasks.Targets" />
<PropertyGroup>
<Configuration>Debug</Configuration>
<Platform>x86</Platform>
<CSConfiguration>$(Configuration)</CSConfiguration>
<BuildType Condition=" '$(BuildType)' == '' ">Build</BuildType>
<PauseBuildOnError>true</PauseBuildOnError>
<PublishWebSites>false</PublishWebSites>
<IsFormalBuild>false</IsFormalBuild>
<VersionName>Prod</VersionName>
</PropertyGroup>
<Target Name="CreateProperties" >
<CreateProperty Value="%(SourcesPathItem.Fullpath)Src\">
<Output PropertyName="SourcesPath" TaskParameter="Value"/>
</CreateProperty>
<CreateProperty Value="%(SourcesPathItem.Fullpath)Artifacts\">
<Output PropertyName="MainArtifactsFolder" TaskParameter="Value"/>
</CreateProperty>
<CreateProperty Value="%(SourcesPathItem.Fullpath)Packages\">
<Output PropertyName="PackageFolder" TaskParameter="Value"/>
</CreateProperty>
<CreateProperty Value="%(SourcesPathItem.Fullpath)Artifacts\DeployedArtifacts\">
<Output PropertyName="DeployedPackageFolder" TaskParameter="Value"/>
</CreateProperty>
<CreateProperty Value="%(SourcesPathItem.Fullpath)Src\Util\InspectorWebService\InspectorWebService\Publish\">
<Output PropertyName="InspectorWebServicePublishPath" TaskParameter="Value"/>
</CreateProperty>
</Target>
<PropertyGroup>
<CSPlatformIndependentProjectProperties>Configuration=$(CSConfiguration);Platform=AnyCPU</CSPlatformIndependentProjectProperties>
<CSPlatformSpecificProjectProperties>Configuration=$(CSConfiguration);Platform=$(Platform)</CSPlatformSpecificProjectProperties>
<VCConfiguration>Configuration=$(CSConfiguration);Platform=Win32</VCConfiguration>
</PropertyGroup>
<Target Name="InspectorWebService">
<RemoveDir Directories="$(InspectorWebServicePublishPath)"/>
<MSBuild Projects="$(SourcesPath)Util\InspectorWebService\InspectorWebService\InspectorWebService.csproj" Targets="$(BuildType)" Properties="$(CSPlatformIndependentProjectProperties)"/>
<MSBuild Condition=" '$(BuildType)' != 'Clean' And '$(PublishWebSites)' == 'true' " Projects="$(SourcesPath)Util\InspectorWebService\InspectorWebService\InspectorWebService.csproj"
Targets="ResolveReferences;_WPPCopyWebApplication" Properties="WebProjectOutputDir=$(InspectorWebServicePublishPath);BuildingProject=true" />
</Target>
<PropertyGroup>
<AllProcessesTargets>
InspectorWebService;
</AllProcessesTargets>
</PropertyGroup>
<Target Name="SW">
<CallTarget Targets="$(AllProcessesTargets)" RunEachTargetSeparately="false"/>
<OnError ExecuteTargets="PauseBuild"/>
</Target>
<Target Name="FormalBuild">
<CallTarget Targets="SW;PreparePackFolder;Pack"/>
<OnError ExecuteTargets="ErrorHandler"/>
</Target>
<Target Name="PreparePackFolder">
<RemoveDir Directories="$(MainArtifactsFolder)" />
<MakeDir Directories="$(MainArtifactsFolder)" />
<MSBuild Projects="$(MSBuildProjectFile)" Targets="PreparePackFolderInternal" Properties="ArtifactFormat=Old;MixedArtifiactFolder=$(MainArtifactsFolder)MixedArtifacts\"/>
<MSBuild Projects="$(MSBuildProjectFile)" Targets="PreparePackFolderInternal" Properties="ArtifactFormat=New;MixedArtifiactFolder=$(MainArtifactsFolder)DeployedArtifacts\"/>
</Target>
<Target Name="PreparePackFolderInternal">
<CallTarget Targets="PrepareInspectorWebServiceToPack;PrepareOtherFolders"/>
</Target>
<Target Name="CopyDefaultFiles">
<Exec Condition=" '$(ArtifactFormat)' == 'Old'" Command="xcopy "$(CompleteBinFolder)*.*" "$(MixedArtifiactFolder)$(ComponenetName)\Binaries" /I /Y /D /E /F"/>
<Exec Condition=" '$(ArtifactFormat)' == 'New'" Command="xcopy "$(CompleteBinFolder)*.*" "$(MixedArtifiactFolder)$(ComponenetName)" /I /Y /D /E /F"/>
<ItemGroup>
<GeneralConfigFiles Include="$(MixedArtifiactFolder)$(ComponenetName)\Binaries\*.config"/>
<PDBFiles Include="$(MixedArtifiactFolder)$(ComponenetName)\**\*.pdb"/>
</ItemGroup>
<Move Condition=" '$(ArtifactFormat)' == 'Old'" SourceFiles="#(GeneralConfigFiles)" DestinationFolder="$(MixedArtifiactFolder)$(ComponenetName)\Configurations"/>
<Move Condition=" '$(ArtifactFormat)' == 'New'" SourceFiles="#(PDBFiles)" DestinationFolder="$(MainArtifactsFolder)PDBs\$(ComponenetName)"/>
<Delete Condition=" '$(ArtifactFormat)' == 'Old'" Files="#(PDBFiles)"/>
</Target>
<Target Name="PrepareInspectorWebServiceToPack" Condition=" '$(BuildType)' != 'Clean' ">
<MSBuild Projects="$(MSBuildProjectFile)" Targets="CopyDefaultFiles" Properties="CompleteBinFolder=$(InspectorWebServicePublishPath);ComponenetName=InspectorWebService"/>
</Target>
<Target Name="PrepareOtherFolders">
<Exec Command="xcopy "$(SourcesPath)..\Certificates\*.*" "$(MixedArtifiactFolder)Certificates" /I /Y /D /E /F"/>
<Exec Command="xcopy "$(SourcesPath)\Resources\CCI\*.*" "$(DeployedPackageFolder)CCI\Configuration\" /I /Y /D /E /F"/>
</Target>
<Target Name="Pack" Condition=" '$(BuildType)' != 'Clean' ">
<RemoveDir Directories="$(PackageFolder)" />
<MakeDir Directories="$(PackageFolder)" />
<ItemGroup>
<InspectorWebServiceFilesForZip Include="$(DeployedPackageFolder)InspectorWebService\**\*.*" Exclude="$(DeployedPackageFolder)InspectorWebService\**\*.pdb" />
</ItemGroup>
<Zip ZipFileName="$(PackageFolder)$(VersionName)-InspectorWebService.zip" WorkingDirectory="$(DeployedPackageFolder)InspectorWebService" Files="#(InspectorWebServiceFilesForZip)" ZipLevel="9" ParallelCompression="false" />
<ItemGroup>
<AllZipFiles Include="$(DeployedPackageFolder)\**\*.*" Exclude="$(DeployedPackageFolder)\**\*.pdb" />
</ItemGroup>
<Zip ZipFileName="$(PackageFolder)$(VersionName)-!All.zip" WorkingDirectory="$(DeployedPackageFolder)" Files="#(AllZipFiles)" ZipLevel="9" ParallelCompression="false" />
<ItemGroup>
<AllPDBFiles Include="$(MainArtifactsFolder)PDBs\**\*.pdb"/>
</ItemGroup>
<Zip ZipFileName="$(PackageFolder)$(VersionName)-!PDBForAll.zip" WorkingDirectory="$(MainArtifactsFolder)PDBs" Files="#(AllPDBFiles)" ZipLevel="9" ParallelCompression="false" />
</Target>
<Target Name="Clean" Condition=" '$(BuildType)' == 'Clean' ">
<RemoveDir Directories="$(InspectorWebServicePublishPath)"/>
<RemoveDir Directories="$(PackageFolder)"/>
<RemoveDir Directories="$(MixedArtifiactFolder)"/>
</Target>
<Target Name="PauseBuild" Condition=" '$(PauseBuildOnError)' == 'true' ">
<Prompt Text="Press any key to continue ..." />
</Target>
<Target Name="ErrorHandler">
</Target>
</Project>
I want to embed local references in the assembly before compiling the main unit. But the written target does not work.
<Target Name="EmbedLocal" BeforeTargets="CoreCompile">
<Message Text="Run EmbedLocal for $(MSBuildProjectFullPath)..." Importance="high"/>
<ItemGroup>
<EmbeddedResource Include="#( ReferencePath->WithMetadataValue( 'CopyLocal', 'true' )->Metadata( 'FullPath' ) )"/>
</ItemGroup>
<Message Text="Embed local references complete for $(OutputPath)$(TargetFileName)." Importance="high" />
</Target>
#(EmbeddedResource) at this moment contains valid list of paths.
Update:
Now my import file contains:
<Project ToolsVersion="$(MSBuildToolsVersion)" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<EmbedLocalReferences Condition=" '$(EmbedLocalReferences)' == '' ">True</EmbedLocalReferences>
</PropertyGroup>
<Target Name="EmbedLocal" BeforeTargets="ResolveReferences" Condition=" '$(EmbedLocalReferences)' == 'True' ">
<Message Text="Run EmbedLocal for $(MSBuildProjectFullPath)..." Importance="high"/>
<ItemGroup>
<EmbeddedResource Include="#(ReferenceCopyLocalPaths->WithMetadataValue( 'Extension', '.dll' )->Metadata( 'FullPath' ))">
<LogicalName>%(ReferenceCopyLocalPaths.Filename)%(ReferenceCopyLocalPaths.Extension)</LogicalName>
</EmbeddedResource>
</ItemGroup>
<Message Text="Embed local references complete for $(OutputPath)$(TargetFileName)." Importance="high" />
</Target>
</Project>
It works fine. Output assembly contains all .dll references as EmbeddedResource.
MSBuild. Create EmbeddedResource before build
You can try to use BeforeBuild action to the csproj file to include the embedded resources:
<Target Name="BeforeBuild">
...
<ItemGroup>
<EmbeddedResource Include="..."/>
</ItemGroup>
...
</Target>
Now MSBuild will add this file as embedded resource into your assembly.
Update:
Thanks #Martin Ullrich. He pointed out the correct direction, we could use <Target Name="EmbedLocal" BeforeTargets="PrepareForBuild"> in the Directory.Build.props to resolve this issue. You can check if it works for you.
<Target Name="EmbedLocal" BeforeTargets="PrepareForBuild">
...
<ItemGroup>
<EmbeddedResource Include="..."/>
</ItemGroup>
...
</Target>
I am trying to get the Unmanaged Export Basic sample working.
The steps I am following:
Create a new classlibrary project.
Add the UnmanagedExports with
nuget.
Change CPU target to x86.
Add the code from the tutorial I am following to the .cs file.
Build
The project is built sucesfully, but when I inspect my dll with DLL Export Viewer I can not see any of my functions.
I am using 32 bits OS and SharpDevelop 4.4 (I also have tried with other SharpDevelop versions and with 64bits OS with the same result).
My sln file:
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "test", "test\test.csproj", "{AFAA816C-65B2-4B58-9FB2-EB7482AA0F5F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{AFAA816C-65B2-4B58-9FB2-EB7482AA0F5F}.Debug|x86.ActiveCfg = Debug|x86
{AFAA816C-65B2-4B58-9FB2-EB7482AA0F5F}.Debug|x86.Build.0 = Debug|x86
{AFAA816C-65B2-4B58-9FB2-EB7482AA0F5F}.Release|x86.ActiveCfg = Release|x86
{AFAA816C-65B2-4B58-9FB2-EB7482AA0F5F}.Release|x86.Build.0 = Release|x86
EndGlobalSection
EndGlobal
My csproj file:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<PropertyGroup>
<ProjectGuid>{AFAA816C-65B2-4B58-9FB2-EB7482AA0F5F}</ProjectGuid>
<ProjectTypeGuids>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<OutputType>Library</OutputType>
<RootNamespace>test</RootNamespace>
<AssemblyName>test</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<AppDesignerFolder>Properties</AppDesignerFolder>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'x86' ">
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>bin\Debug\</OutputPath>
<DebugSymbols>True</DebugSymbols>
<DebugType>Full</DebugType>
<Optimize>False</Optimize>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>bin\Release\</OutputPath>
<DebugSymbols>False</DebugSymbols>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Reference Include="RGiesecke.DllExport.Metadata">
<HintPath>..\packages\UnmanagedExports.1.2.7\lib\net\RGiesecke.DllExport.Metadata.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="MyClass.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
My cs file:
using System;
using System.Collections.Generic;
using System.Text;
using RGiesecke.DllExport;
using System.Runtime.InteropServices;
namespace Testme
{
class Test
{
[DllExport("Add", CallingConvention = CallingConvention.StdCall)]
public static int Add(int left, int right)
{
return left + right;
}
........
Dll Export Viewer of my dll
Dll Export Viewer of a working dll (downloaded from the tutorial web)
Both dlls (mine and the downloaded) have the same size for my OS but not for the DLL Export Viewer.
What I am missing??
I had the same problem and I solved it this way,
You need add the follow line below this line csproj file
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- Remove this comment and insert This line-->
<Import Project="packages/UnmanagedExports.1.2.7/tools/RGiesecke.DllExport.targets" Condition="Exists('packages/UnmanagedExports.1.2.7/tools/RGiesecke.DllExport.targets')"/>
Check file exist in your folder "packages/UnmanagedExports.1.2.7/tools/RGiesecke.DllExport.targets"